[Python-bugs-list] [ python-Bugs-676990 ] memory leak in pyexpat.c::my_ElementDeclHandler()

SourceForge.net noreply@sourceforge.net
Sat, 01 Feb 2003 14:40:58 -0800


Bugs item #676990, was opened at 2003-01-29 14:52
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=676990&group_id=5470

Category: XML
Group: Python 2.3
Status: Open
>Resolution: Accepted
Priority: 6
Submitted By: Neal Norwitz (nnorwitz)
>Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: memory leak in pyexpat.c::my_ElementDeclHandler()

Initial Comment:
Fred, I'm assigning to you since you've seen this once
already. :-)  Not sure who would know best how to fix
this problem.  Perhaps Martin, but he's on vacation.

As of now, 2003/1/29, there is a memory leak in
xmlparse.c::doProlog() line 3979.

The XML_Content is dynamically allocated, but never
freed in the block.  The lifetime of the variable
content is not clear.  It is passed to
elementDeclHandler().  Does content need to be dynamic,
or can it be a local (stack) variable?  Does
elementDeclHandler() take ownership of content?

I can make the change in Python (which is where this
problem was found from test_minidom).

20 bytes in 1 blocks are definitely lost in loss record
2 of 15
  at 0x4015D480: malloc (vg_clientfuncs.c:100)
doProlog (Modules/expat/xmlparse.c:3979)
prologProcessor (Modules/expat/xmlparse.c:3185)
prologInitProcessor (Modules/expat/xmlparse.c:3016)
XML_ParseBuffer (Modules/expat/xmlparse.c:1439)
XML_Parse (Modules/expat/xmlparse.c:1427)
xmlparse_Parse (Modules/pyexpat.c:853)

This problem was originally from this bug report in expat:

http://sf.net/tracker/?func=detail&atid=110127&aid=676926&group_id=10127


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

>Comment By: Neal Norwitz (nnorwitz)
Date: 2003-02-01 17:40

Message:
Logged In: YES 
user_id=33168

I used valgrind on test_minidom.  This patch does fix the leak.

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

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2003-01-31 12:22

Message:
Logged In: YES 
user_id=3066

Oops, patch really attached now.

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

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2003-01-30 10:38

Message:
Logged In: YES 
user_id=3066

The attached patch frees the content model passed to the
handler.  This should fix the leak; please test using
whatever tool you used to discover this.

Thanks!

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

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2003-01-30 09:44

Message:
Logged In: YES 
user_id=3066

Fixed summary.

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

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2003-01-29 15:03

Message:
Logged In: YES 
user_id=3066

As noted in the Expat tracker, this is not a memory leak in 
Expat, but in pyexpat.  I've taken a quick look at the relevant 
code in pyexpat; it won't be hard to fix, but it will take longer 
than writing this response.  I'll try to knock it out tonight.

(For the record: this isn't due to any changes in Expat, it's 
just that the bug in pyexpat has only now been caught.)

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

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