BUG? PyMem_Free vs strdup

Skip Montanaro skip at pobox.com
Wed Nov 5 18:51:52 CET 2003

    Robin> the storage is allocated and freed thusly

    Robin> s = strdup(PyString_AsString(v)); 
    Robin> .....
    Robin> PyMem_Free(s);


    Robin> I don't think I've done something to change the bytes, but can I
    Robin> mix strdup allocated memory with the "Python heap" which is what
    Robin> the manual talks about or is this a bug?

Memory allocated by strdup() should almost certainly be freed with free(),
not PyMem_Free().

    Robin> Is there an easy way to get a grasp on the various memory
    Robin> allocation functions?

Sure.  Keep your allocations and deallocations within the same family of
functions. ;-)


More information about the Python-list mailing list