[xml] libxml and threads



Dear all,

sorry for asking about on the mailing list, but I did not find anything on the web site.
I have a multithreaded application in which each thread uses libxml2 for parsing in memory xml buffers etc.

Everything works fine, but I have found that many memory leaks are associated with libxml2 APIs. The leaks are small, but they are so many that this is a serious problem. Now, I strongly believe that it is entirely my fault, but I need to understand exactly how to use libxml2 in threaded applications.

Here is a sample memory leak:


Leak: 0x0110f690 size=48 string 'MUTX'
Call stack: [thread 280c000]: | 0x0 | _pthread_body | thread_starter | provider_thr | grelc_get_sql | xmlSAXParseMemoryWithData | xmlCreateMemoryParserCtxt | xmlNewParserCtxt | xmlInitParserCtxt | xmlDefaultSAXHandlerInit | __xmlDefaultSAXHandler | xmlGetGlobalState | xmlNewGlobalState | xmlInitializeGlobalState | xmlInitGlobals | xmlNewMutex | malloc | malloc_zone_malloc

It looks like a mutex object is never deallocated.

The code looks like

xmlDocPtr doc;
...

doc = xmlParseMemory (docname, strlen(docname) - 1);
...
xmlCleanupParser();


Is this the way to write this kind of code? I was not able to find any example of threaded code. I have found some APIs for dealing with threads tough.
Placing a xmlLockLibrary() and xmlUnlockLibrary() before and after to model a critical section does not help (the same holds if I create a mutex object and call related lock/unlock functions). The libxml2 I am using is the latest one officially released on January. I am working on Mac oS X 10.3.8

Thanks in advance,
Massimo


--

*************************************************************************************

Massimo Cafaro, Ph.D. Center for Advanced Computational Technologies
Assistant Professor Voice +39 0832 297371
University of Lecce, Italy Fax +39 0832 297279
Faculty of Engineering E-mail massimo cafaro unile it
Via per Monteroni cafaro cacr caltech edu
73100 Lecce, Italy Web http://sara.unile.it/~cafaro

*************************************************************************************

Attachment: PGP.sig
Description: This is a digitally signed message part



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