[xml] Newbie memory allocation problem with xmlDocDumpFormatMemory



Hi all, I had a question with freeing memory after serializing an XML
document into a (char *).    The documentation for
xmlDocDumpFormatMemory says:

"""
Dump an XML document in memory and return the #xmlChar * and it's
size. It's up to the caller to free the memory with xmlFree()
"""

I can't seem to find an xmlFree function defined, but I did find
xmlMemFree which doesn't seem to have any documentation currently:

http://xmlsoft.org/html/libxml-xmlmemory.html#xmlMemFree
 
Here's some code that shows what I'm trying to do (I'm using Pyrex to
do Python->libxml2 bindings).

      1 def (xmlDocPtr myDoctPtr):
      2     unsigned char* xmlbuff
      3     int buffersize
      4     xmlDocDumpFormatMemory(docPtr, &xmlbuff, &buffersize, 1)
      5     result = str(<char *> xmlbuff)
      6     xmlMemFree(xmlbuff)
      7     return result

The xmlMemFree function has some comments that it's only to be used
for debugging.

So my questions are - should I be using xmlMemFree or xmlFree?

If I'm supposed to use xmlFree - which header is xmlFree(*ptr) declared?

thanks,
vic



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