[Patches] [ python-Patches-587889 ] fix memory leak of tp_doc in typeobject

noreply@sourceforge.net noreply@sourceforge.net
Mon, 29 Jul 2002 09:58:09 -0700


Patches item #587889, was opened at 2002-07-28 23:10
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=587889&group_id=5470

Category: Core (C code)
Group: Python 2.3
Status: Open
>Resolution: Accepted
Priority: 5
Submitted By: Neal Norwitz (nnorwitz)
>Assigned to: Neal Norwitz (nnorwitz)
Summary: fix memory leak of tp_doc in typeobject

Initial Comment:
Attached is a patch which fixes a memory leak in
typeobject.c.  I would have checked this in, but there
was a line which concerned me in
Objects/structseq.c::PyStructSequence_InitType():343. 
In this function, it assigns the tp_doc from a
PyStructSequence_Desc* which is passed in.  I'm not
sure where this memory comes from, so I wasn't sure if
the patch would create problems.

The memory leak was found by using valgrind: 
http://developer.kde.org/~sewardj/

Another thing I saw was that it *may* be possible that
the __doc__ is not a string.  But in two places there
were PyString_FromString (1 was the macro).  The only
way I can see a non-string in tp_doc is from the
InitType function in structseq.  I haven't traced it
further, so if structseq can only have a string, there
shouldn't be a problem.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-07-29 12:57

Message:
Logged In: YES 
user_id=6380

PyStructSequence_InitType() initializes a *static* type,
which will never be passed to type_dealloc(). In particular,
PyStructSequence_InitType() copies a template over the type
object which has the default flags in tp_flags, and the
default flags don't include the HEAPTYPE flag that
type_dealloc asserts.

IOW don't worry about that.

While __doc__ may not always be a string, tp_doc is always a
char *.

Instead of PyObject_DEL(), why not use PyObject_Free()? The
macro expands to a call to the function anyway.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=587889&group_id=5470