Re: [gdome]Memory Leaks



On Mon, Feb 04, 2002 at 09:07:07PM -0500, T.J. Mather wrote:
> I've run through all of the gdomecore tests, and fixed all the memory 
> leaks that these tests uncovered.  To test, I wrapped the code in a 
> while(1) loop and ran top.  If anybody knows a better way of testing for 
> memory leaks, please let me know :-)

  Use the xmlMemSetup routine to activate the debug memory wrapper
  http://xmlsoft.org/html/libxml-xmlmemory.html#XMLMEMSETUP

at startup and use xmlMemUsed() and xmlMemoryDump() to track the blocks
allocated an not freed.

extern void xmlMemFree(void *ptr);
extern void *xmlMemMalloc(size_t size);
extern void *xmlMemRealloc(void *ptr,size_t size);
extern char *xmlMemoryStrdup(const char *str);

ret = (long) xmlMemSetup(xmlMemFree, xmlMemMalloc,
		         xmlMemRealloc, xmlMemoryStrdup);

the main problem with this approach is that the blocks allocated 
by the library must be dealloacted using xmlFree() or you app will
segfault. It also doesn't covers blocks not allocated with xmlMalloc/
xmlRealloc/xmlStrdup.

Check the beginning of the python/libxml.c code in the new Python wrappers
they do that precisely.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]