Bug in _PyUnicode_ClearStaticStrings() method of unicodeobject.c

Prashant Kurnawal prashantkurnawal_j at yahoo.in
Thu Dec 27 11:35:20 CET 2012


Hi,
 
I have embedded python3.3 in my application.
I got a crash when I ran a sample python script using it.
 
As per my assumption, On interpreter shutdown, all strings are released (through _PyUnicode_ClearStaticStrings). (Found in one of the comments of object.h file)
 
When I tried to debug python source, I found a defect in _PyUnicode_ClearStaticStrings() method.
 
 
void
_PyUnicode_ClearStaticStrings()
{
     _Py_Identifier *i;
      for (i = static_strings; i; i = i->next) {
           Py_DECREF(i->object);
           i->object = NULL;
           i->next = NULL;
      }
}
 
Here, for loop will not free all the static strings. It will free only the first static string in the list.
This loop needs to be corrected.
 
I corrected the loop in following way and its working fine for me.
 
void
_PyUnicode_ClearStaticStrings()
{
    _Py_Identifier *i;
    while(static_strings->next != NULL)
    {
        i = static_strings;
        static_strings = static_strings->next;
        Py_DECREF(i->object);
        i->object = NULL;
        i->next = NULL;
    }
    
    Py_DECREF(static_strings->object);
    static_strings->object = NULL;
    static_strings = NULL;
}
 
Please let me know if this is a defect or it is done so intentionally.
Please reply as soon as possible.

Thanks and Regards,
Prashant.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-bugs-list/attachments/20121227/b3eddfd4/attachment.html>


More information about the Python-bugs-list mailing list