1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-30 22:43:14 +03:00

serious changes on Result Value Trees and NodeSets w.r.t. deallocation and

* xpath.c: serious changes on Result Value Trees and NodeSets
  w.r.t. deallocation and collect operations. Probably not
  100% clean (merge of allocated trees smells like a problem).
  Seems sufficient to close #58943
Daniel
This commit is contained in:
Daniel Veillard
2001-08-14 16:43:10 +00:00
parent 90493a9171
commit 0ab5caba5b
2 changed files with 37 additions and 12 deletions

View File

@ -1,3 +1,10 @@
Tue Aug 14 18:37:23 CEST 2001 Daniel Veillard <daniel@veillard.com>
* xpath.c: serious changes on Result Value Trees and NodeSets
w.r.t. deallocation and collect operations. Probably not
100% clean (merge of allocated trees smells like a problem).
Seems sufficient to close #58943
Tue Aug 14 16:12:00 CEST 2001 Daniel Veillard <daniel@veillard.com> Tue Aug 14 16:12:00 CEST 2001 Daniel Veillard <daniel@veillard.com>
* xmllint.c: adding a --format option * xmllint.c: adding a --format option

42
xpath.c
View File

@ -1737,7 +1737,7 @@ xmlXPathFreeValueTree(xmlNodeSetPtr obj) {
if (obj == NULL) return; if (obj == NULL) return;
for (i = 0;i < obj->nodeNr;i++) for (i = 0;i < obj->nodeNr;i++)
if (obj->nodeTab[i] != NULL) if (obj->nodeTab[i] != NULL)
xmlFreeNodeList(obj->nodeTab[i]); xmlFreeNodeList(obj->nodeTab[i]);
if (obj->nodeTab != NULL) { if (obj->nodeTab != NULL) {
@ -1834,6 +1834,8 @@ xmlXPathNewValueTree(xmlNodePtr val) {
} }
memset(ret, 0 , (size_t) sizeof(xmlXPathObject)); memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
ret->type = XPATH_XSLT_TREE; ret->type = XPATH_XSLT_TREE;
ret->boolval = 1;
ret->user = (void *) val;
ret->nodesetval = xmlXPathNodeSetCreate(val); ret->nodesetval = xmlXPathNodeSetCreate(val);
return(ret); return(ret);
} }
@ -2824,14 +2826,19 @@ xmlXPathObjectCopy(xmlXPathObjectPtr val) {
break; break;
case XPATH_XSLT_TREE: case XPATH_XSLT_TREE:
if ((val->nodesetval != NULL) && if ((val->nodesetval != NULL) &&
(val->nodesetval->nodeTab != NULL)) (val->nodesetval->nodeTab != NULL)) {
ret->boolval = 1;
ret->user = xmlCopyNode(val->nodesetval->nodeTab[0], 1);
ret->nodesetval = xmlXPathNodeSetCreate( ret->nodesetval = xmlXPathNodeSetCreate(
xmlCopyNode(val->nodesetval->nodeTab[0], 1)); (xmlNodePtr) ret->user);
else } else
ret->nodesetval = xmlXPathNodeSetCreate(NULL); ret->nodesetval = xmlXPathNodeSetCreate(NULL);
/* Deallocate the copied tree value */
break; break;
case XPATH_NODESET: case XPATH_NODESET:
ret->nodesetval = xmlXPathNodeSetMerge(NULL, val->nodesetval); ret->nodesetval = xmlXPathNodeSetMerge(NULL, val->nodesetval);
/* Do not deallocate the copied tree value */
ret->boolval = 0;
break; break;
case XPATH_LOCATIONSET: case XPATH_LOCATIONSET:
#ifdef LIBXML_XPTR_ENABLED #ifdef LIBXML_XPTR_ENABLED
@ -2860,10 +2867,12 @@ xmlXPathObjectCopy(xmlXPathObjectPtr val) {
void void
xmlXPathFreeObject(xmlXPathObjectPtr obj) { xmlXPathFreeObject(xmlXPathObjectPtr obj) {
if (obj == NULL) return; if (obj == NULL) return;
if (obj->type == XPATH_NODESET) { if ((obj->type == XPATH_NODESET) || (obj->type == XPATH_XSLT_TREE)) {
if (obj->boolval) { if (obj->boolval) {
obj->type = XPATH_XSLT_TREE; if (obj->user != NULL) {
if (obj->nodesetval != NULL) xmlFreeNodeList((xmlNodePtr) obj->user);
xmlXPathFreeNodeSet(obj->nodesetval);
} else if (obj->nodesetval != NULL)
xmlXPathFreeValueTree(obj->nodesetval); xmlXPathFreeValueTree(obj->nodesetval);
} else { } else {
if (obj->nodesetval != NULL) if (obj->nodesetval != NULL)
@ -2877,9 +2886,6 @@ xmlXPathFreeObject(xmlXPathObjectPtr obj) {
} else if (obj->type == XPATH_STRING) { } else if (obj->type == XPATH_STRING) {
if (obj->stringval != NULL) if (obj->stringval != NULL)
xmlFree(obj->stringval); xmlFree(obj->stringval);
} else if (obj->type == XPATH_XSLT_TREE) {
if (obj->nodesetval != NULL)
xmlXPathFreeValueTree(obj->nodesetval);
} }
xmlFree(obj); xmlFree(obj);
@ -8402,8 +8408,14 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
"\nExamined %d nodes, found %d nodes at that step\n", "\nExamined %d nodes, found %d nodes at that step\n",
t, n); t, n);
#endif #endif
xmlXPathFreeObject(obj);
valuePush(ctxt, xmlXPathWrapNodeSet(ret)); valuePush(ctxt, xmlXPathWrapNodeSet(ret));
if ((obj->boolval) && (obj->user != NULL)) {
ctxt->value->boolval = 1;
ctxt->value->user = obj->user;
obj->user = NULL;
obj->boolval = 0;
}
xmlXPathFreeObject(obj);
return(t); return(t);
} }
@ -8780,8 +8792,14 @@ xmlXPathNodeCollectAndTestNth(xmlXPathParserContextPtr ctxt,
"\nExamined %d nodes, found %d nodes at that step\n", "\nExamined %d nodes, found %d nodes at that step\n",
t, list->nodeNr); t, list->nodeNr);
#endif #endif
xmlXPathFreeObject(obj);
valuePush(ctxt, xmlXPathWrapNodeSet(list)); valuePush(ctxt, xmlXPathWrapNodeSet(list));
if ((obj->boolval) && (obj->user != NULL)) {
ctxt->value->boolval = 1;
ctxt->value->user = obj->user;
obj->user = NULL;
obj->boolval = 0;
}
xmlXPathFreeObject(obj);
return(t); return(t);
} }