[xslt] weird xmlFree behavior and interaction with xslt



hi all,

i'm seeing a weird behavior that probably stems from using
libxml/libxslt in a non-standard way. i am nonetheless perplexed.

the issue arises from attempting to stream top-level xmlNodes as if
the xmlParserCtxt is a pull parser.

i would like to avoid reading in a whole xml file, so i have an
xmlNode* getNextNode() function that calls xmlParseChunk() when it
needs to.

by "when it needs to", i mean it hands buffers to xmlParseChunk until
there is another top-level xmlNode *and* that node isn't the last
top-level node. said node is then xmlUnlinkNode'd, used, and possibly
operated upon and xmlFreeNode'd.

my thinking here is that if the parser hasn't finished building a node
yet, there may be some dangling references that would cause trouble.
by waiting until there is at least one more xmlNode, i hope to avoid
messing with things in progress.

this works fine when i use the node and free it.

if i use the node in a transformation, i often see xmlFree errors when
freeing the node.

here's a distilled code snippet of what i do with a node:

void item(xmlNode* node) {
 if (xslt_ != NULL) {
   xmlDoc* doc = xmlNewDoc((xmlChar*) "1.0");
   xmlDocSetRootElement(doc, node);
   xmlDoc* res = xsltApplyStylesheet(xslt_, doc, NULL);
   xmlFreeDoc(doc);  // free the made-up doc and input node <<---
causes breakage
   xmlOut(xmlDocGetRootElement(res));
   xmlFreeDoc(res);  // free the result
 } else {
   xmlOut(node);
   xmlFreeNode(node);
 }
}

if i don't transform the node, all is happy. if i don't attempt to
free the node after using it in a transformation, all is happy (but my
process size grows). if i read in the whole xml file and walk through
the top-level nodes, all is happy.

ideas and suggestions welcome.

-bart


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