[xml] Memory overlap with apr



I'm experimenting some memory overlap with apr pools.
I wrote an apache module (apache 2.2.4) which uses memory allocations from r->pool (which is an apr pool).
Inside the module I use libxml2 to handle, parse my xml documents.
It seems that libxml2, when I try to free the documents, tries to access apr memory giving a segmentation fault.
At first in my module I used directly xmlFreeDoc(doc) and  xmlFree(bufptr):

xmlDocDumpMemoryEnc(doc, &bufptr, &size, "UTF-8");
putXML(r, (char*)bufptr);

if (size > 0)
  xmlFree(bufptr);

if (docinter != NULL)
      xmlFreeDoc(docinter);
if (docs != NULL)
      xmlFreeDoc(docs);

xmlFreeDoc(doc);
xmlCleanupParser();
return OK;


while now, following the advice of Nick Kew (an expert apache developer) I use apr_pool_cleanup_register:

So after the creation or parsing of xml documents:

apr_pool_cleanup_register(r->pool, doc, liberaDoc, apr_pool_cleanup_null);

and after dump xml doc:

xmlDocDumpMemoryEnc(doc, &bufptr, &size, "UTF-8");
apr_pool_cleanup_register(r->pool, bufptr, liberaBuff, apr_pool_cleanup_null);

where:

apr_status_t liberaDoc(void *d)
{
  xmlDocPtr doc = d;
    if (doc != NULL)
      xmlFreeDoc(doc);
    return APR_SUCCESS;
}

apr_status_t liberaBuff(void *b)
{
  xmlChar *bufptr = b;
    if (bufptr != NULL)
      xmlFree(bufptr);
    return APR_SUCCESS;
}

The problem is not changed: during xmlFreeDoc sometimes I get a Segmentation fault. Is it possible to have a memory overlap between apr pools and libxml2 memory allocation (which uses malloc and free)? If it is true, could I use xmlMemSetup to overwrite the memory allocation from apr ones? The problem is that the functions like xmlMallocFunc doesn't get as parametrs any pointer to for example apr pools.
Any ideas?
Best regards

Marco





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