log4cxx 0.9.7: Fix for memory leak in gnomexml.cpp when parsing configuration file (Linux)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

log4cxx 0.9.7: Fix for memory leak in gnomexml.cpp when parsing configuration file (Linux)

RUOFF, LARS (LARS)

Hi,

FYI, another memory leak we found in log4cxx 0.9.7 (this is an old version!):

During parsing, allocated XML attributes are not freed again.

Detected with valgrind/memcheck analysis.

 

Here’s a fix:

(Base is 0.9.7)

\src\gnomexml.cpp:

 

@@ -126,6 +126,7 @@

                                   if (attributeValue != 0

                                               && elementId == A2T(attributeValue))

                                   {

+                                              xmlFree(attributeValue);

                                               return new GnomeXMLDOMElement(node);

                                   }

                       }

@@ -178,7 +179,18 @@

           USES_CONVERSION;

           char * attributeValue = (char *)xmlGetProp(

                       element, (const xmlChar *)T2A(name.c_str()));

-           return (attributeValue == 0) ? String() : A2T(attributeValue);

+          String ret;

+          if (attributeValue == 0)

+          {

+                      ret=String();

+          }

+          else

+          {

+                      ret=A2T(attributeValue);

+                      xmlFree(attributeValue);

+          }

+          return ret;

+          //return (attributeValue == 0) ? String() : A2T(attributeValue);

}

 // GnomeXMLDOMNodeList

 

 

Best regards,

Lars Ruoff

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: log4cxx 0.9.7: Fix for memory leak in gnomexml.cpp when parsing configuration file (Linux)

Rhys Ulerich-2
> FYI, another memory leak we found in log4cxx 0.9.7 (this is an old
> version!)

Thank you Lars.  It doesn't seem like that code still exists in trunk.
We've no file by that name, and tokens like xmlFree and xmlGetProp do
not appear in the current codebase.

Anyone recognize what we should review in trunk to see if we've got
the same issue currently?

- Rhys
Loading...