summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam M. Brack <wbrack@src.gnome.org>2003-12-30 08:30:19 +0000
committerWilliam M. Brack <wbrack@src.gnome.org>2003-12-30 08:30:19 +0000
commit72ee48d55f9002544d011826e2897b5054b7e32c (patch)
tree91b1358d7a0ab850f72bc8338cc250021a188763
parent1f5c9891a08c20709a59ab004b84b934d3c2e5d8 (diff)
downloadlibxml2-72ee48d55f9002544d011826e2897b5054b7e32c.tar.gz
Fixed memory leak reported by Dave Beckett Removed spurious comment
* parser.c, xmlmemory.c, include/libxml/xmlmemory.h: Fixed memory leak reported by Dave Beckett * xmlschemas.c: Removed spurious comment reported on the mailing list * xinclude.c, xpath.c, xpointer.c, libxml/include/xpointer.h: Further work on Bug 129967 concerning xpointer range handling and range-to function; much better, but still not complete
-rw-r--r--ChangeLog10
-rw-r--r--include/libxml/xmlmemory.h5
-rw-r--r--include/libxml/xpointer.h3
-rw-r--r--parser.c1
-rw-r--r--xinclude.c49
-rw-r--r--xmlmemory.c14
-rw-r--r--xmlschemas.c9
-rw-r--r--xpath.c48
-rw-r--r--xpointer.c16
9 files changed, 103 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index cc3f6668..8b88c4e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Tue Dec 30 16:26:13 HKT 2003 William Brack <wbrack@mmm.com.hk>
+
+ * parser.c, xmlmemory.c, include/libxml/xmlmemory.h: Fixed
+ memory leak reported by Dave Beckett
+ * xmlschemas.c: Removed spurious comment reported on the mailing
+ list
+ * xinclude.c, xpath.c, xpointer.c, libxml/include/xpointer.h:
+ Further work on Bug 129967 concerning xpointer range handling
+ and range-to function; much better, but still not complete
+
Mon Dec 29 18:08:05 CET 2003 Daniel Veillard <daniel@veillard.com>
* valid.c: xmlValidateElement could crash for element holding a
diff --git a/include/libxml/xmlmemory.h b/include/libxml/xmlmemory.h
index 3d890d0d..130036ce 100644
--- a/include/libxml/xmlmemory.h
+++ b/include/libxml/xmlmemory.h
@@ -129,6 +129,11 @@ XMLPUBFUN int XMLCALL
XMLPUBFUN int XMLCALL
xmlInitMemory (void);
+/*
+ * Cleanup of the memory layer.
+ */
+XMLPUBFUN void XMLCALL
+ xmlCleanupMemory (void);
/*
* These are specific to the XML debug memory wrapper.
*/
diff --git a/include/libxml/xpointer.h b/include/libxml/xpointer.h
index 7f59eb7f..2856bdd6 100644
--- a/include/libxml/xpointer.h
+++ b/include/libxml/xpointer.h
@@ -103,7 +103,8 @@ XMLPUBFUN xmlNodePtr XMLCALL
xmlXPtrBuildNodeList (xmlXPathObjectPtr obj);
XMLPUBFUN void XMLCALL
xmlXPtrEvalRangePredicate (xmlXPathParserContextPtr ctxt);
-
+XMLPUBFUN xmlNodePtr XMLCALL
+ xmlXPtrAdvanceNode (xmlNodePtr cur);
#ifdef __cplusplus
}
#endif
diff --git a/parser.c b/parser.c
index 02ff0020..e2791021 100644
--- a/parser.c
+++ b/parser.c
@@ -12112,6 +12112,7 @@ xmlCleanupParser(void) {
xmlCleanupGlobals();
xmlResetLastError();
xmlCleanupThreads(); /* must be last if called not from the main thread */
+ xmlCleanupMemory();
xmlParserInitialized = 0;
}
diff --git a/xinclude.c b/xinclude.c
index 3bee9ee2..ca66d622 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -38,7 +38,7 @@
/************************************************************************
* *
- * XInclude contexts handling *
+ * XInclude context handling *
* *
************************************************************************/
@@ -50,7 +50,7 @@ typedef xmlChar *xmlURL;
typedef struct _xmlXIncludeRef xmlXIncludeRef;
typedef xmlXIncludeRef *xmlXIncludeRefPtr;
struct _xmlXIncludeRef {
- xmlChar *URI; /* the rully resolved resource URL */
+ xmlChar *URI; /* the fully resolved resource URL */
xmlChar *fragment; /* the fragment in the URI */
xmlDocPtr doc; /* the parsed document */
xmlNodePtr ref; /* the node making the reference in the source */
@@ -70,12 +70,12 @@ struct _xmlXIncludeCtxt {
int txtNr; /* number of unparsed documents */
int txtMax; /* size of unparsed documents tab */
xmlNodePtr *txtTab; /* array of unparsed text nodes */
- xmlURL *txturlTab; /* array of unparsed txtuments URLs */
+ xmlURL *txturlTab; /* array of unparsed text URLs */
xmlChar * url; /* the current URL processed */
- int urlNr; /* number of url stacked */
- int urlMax; /* size of url stack */
- xmlChar * *urlTab; /* url stack */
+ int urlNr; /* number of URLs stacked */
+ int urlMax; /* size of URL stack */
+ xmlChar * *urlTab; /* URL stack */
int nbErrors; /* the number of errors detected */
int legacy; /* using XINCLUDE_OLD_NS */
@@ -94,7 +94,7 @@ xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree);
/**
* xmlXIncludeErrMemory:
- * @extra: extra informations
+ * @extra: extra information
*
* Handle an out of memory condition
*/
@@ -115,7 +115,7 @@ xmlXIncludeErrMemory(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node,
* @ctxt: the XInclude context
* @node: the context node
* @msg: the error message
- * @extra: extra informations
+ * @extra: extra information
*
* Handle an XInclude error
*/
@@ -136,7 +136,7 @@ xmlXIncludeErr(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node, int error,
* @ctxt: the XInclude context
* @node: the context node
* @msg: the error message
- * @extra: extra informations
+ * @extra: extra information
*
* Emit an XInclude warning.
*/
@@ -341,7 +341,7 @@ xmlXIncludeURLPush(xmlXIncludeCtxtPtr ctxt,
* xmlXIncludeURLPop:
* @ctxt: the parser context
*
- * Pops the top url from the url stack
+ * Pops the top URL from the URL stack
*/
static void
xmlXIncludeURLPop(xmlXIncludeCtxtPtr ctxt)
@@ -402,7 +402,7 @@ xmlXIncludeFreeContext(xmlXIncludeCtxtPtr ctxt) {
* @ctxt: the XInclude context
* @URL: the URL or file path
*
- * parse an document for XInclude
+ * parse a document for XInclude
*/
static xmlDocPtr
xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) {
@@ -419,7 +419,7 @@ xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) {
return(NULL);
}
/*
- * try to ensure that the new document included are actually
+ * try to ensure that new documents included are actually
* built with the same dictionary as the including document.
*/
if ((ctxt->doc != NULL) && (ctxt->doc->dict != NULL) &&
@@ -675,7 +675,7 @@ xmlXIncludeRecurseDoc(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc,
newctxt->urlTab = ctxt->urlTab;
/*
- * Inherit the documents already in use by others includes
+ * Inherit the documents already in use by other includes
*/
newctxt->incBase = ctxt->incNr;
for (i = 0;i < ctxt->incNr;i++) {
@@ -818,11 +818,11 @@ xmlXIncludeCopyNodeList(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
}
/**
- * xmlXInclueGetNthChild:
+ * xmlXIncludeGetNthChild:
* @cur: the node
* @no: the child number
*
- * Returns the @no'th element child of @cur or NULL
+ * Returns the @n'th element child of @cur or NULL
*/
static xmlNodePtr
xmlXIncludeGetNthChild(xmlNodePtr cur, int no) {
@@ -844,8 +844,6 @@ xmlXIncludeGetNthChild(xmlNodePtr cur, int no) {
return(cur);
}
-xmlNodePtr xmlXPtrAdvanceNode(xmlNodePtr cur);
-
/**
* xmlXIncludeCopyRange:
* @ctxt: the XInclude context
@@ -856,7 +854,7 @@ xmlNodePtr xmlXPtrAdvanceNode(xmlNodePtr cur);
* Build a node list tree copy of the XPointer result.
*
* Returns an xmlNodePtr list or NULL.
- * the caller has to free the node tree.
+ * The caller has to free the node tree.
*/
static xmlNodePtr
xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
@@ -884,7 +882,7 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
index1 = range->index;
index2 = range->index2;
while (cur != NULL) {
- if (cur == end) {
+ if (cur == end) { /* Are we at the end of the range? */
if (cur->type == XML_TEXT_NODE) {
const xmlChar *content = cur->content;
int len;
@@ -911,7 +909,7 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
else
xmlAddChild(parent, tmp);
return(list);
- } else {
+ } else { /* ending node not a text node */
tmp = xmlDocCopyNode(cur, target, 0);
if (list == NULL)
list = tmp;
@@ -939,7 +937,7 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
*/
continue; /* while */
}
- } else if ((cur == start) &&
+ } else if ((cur == start) && /* Not at the end, are we at start? */
(list == NULL) /* looks superfluous but ... */ ) {
if ((cur->type == XML_TEXT_NODE) ||
(cur->type == XML_CDATA_SECTION_NODE)) {
@@ -950,12 +948,13 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
} else {
if (index1 > 1) {
content += (index1 - 1);
+ index1 = 0;
}
tmp = xmlNewText(content);
}
last = list = tmp;
- } else {
- if ((cur == start) && (index1 > 1)) {
+ } else { /* Not text node */
+ if (index1 > 1) { /* Do we need to position? */
tmp = xmlDocCopyNode(cur, target, 0);
list = tmp;
parent = tmp;
@@ -967,7 +966,7 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
*/
continue; /* while */
}
- tmp = xmlDocCopyNode(cur, target, 1);
+ tmp = xmlDocCopyNode(cur, target, 0);
list = tmp;
parent = NULL;
last = tmp;
@@ -992,7 +991,7 @@ xmlXIncludeCopyRange(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
/* Humm, should not happen ! */
break;
default:
- tmp = xmlDocCopyNode(cur, target, 1);
+ tmp = xmlDocCopyNode(cur, target, 0);
break;
}
if (tmp != NULL) {
diff --git a/xmlmemory.c b/xmlmemory.c
index 712a967f..d8fa2b9c 100644
--- a/xmlmemory.c
+++ b/xmlmemory.c
@@ -812,6 +812,20 @@ xmlInitMemory(void)
}
/**
+ * xmlCleanupMemory:
+ *
+ * Free up all the memory associated with memorys
+ */
+void
+xmlCleanupMemory(void) {
+ if (xmlMemInitialized == 0)
+ return;
+
+ xmlFreeMutex(xmlMemMutex);
+ xmlMemInitialized = 0;
+}
+
+/**
* xmlMemSetup:
* @freeFunc: the free() function to use
* @mallocFunc: the malloc() function to use
diff --git a/xmlschemas.c b/xmlschemas.c
index e5673373..539465f8 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -901,15 +901,6 @@ xmlSchemaDump(FILE * output, xmlSchemaPtr schema)
* Utilities *
* *
************************************************************************/
-/**
- * numberedString:
- * @prefix: the string prefix
- * @number: the number
- *
- * Build a new numbered string
- *
- * Returns the new string
- */
/**
* xmlSchemaGetProp:
diff --git a/xpath.c b/xpath.c
index 0fa53b80..563e307e 100644
--- a/xpath.c
+++ b/xpath.c
@@ -10307,11 +10307,12 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
ctxt->context->doc = bakd;
ctxt->context->node = bak;
CHECK_ERROR0;
- if (op->ch2 != -1)
+ if (op->ch2 != -1) {
total += xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
- ctxt->context->doc = bakd;
- ctxt->context->node = bak;
- CHECK_ERROR0;
+ ctxt->context->doc = bakd;
+ ctxt->context->node = bak;
+ CHECK_ERROR0;
+ }
return (total);
case XPATH_OP_PREDICATE:
case XPATH_OP_FILTER:{
@@ -10594,7 +10595,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
xmlLocationSetPtr newlocset = NULL;
xmlLocationSetPtr oldlocset;
xmlNodeSetPtr oldset;
- int i;
+ int i, j;
if (op->ch1 != -1)
total +=
@@ -10611,9 +10612,9 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
CHECK_TYPE0(XPATH_LOCATIONSET);
obj = valuePop(ctxt);
oldlocset = obj->user;
- ctxt->context->node = NULL;
if ((oldlocset == NULL) || (oldlocset->locNr == 0)) {
+ ctxt->context->node = NULL;
ctxt->context->contextSize = 0;
ctxt->context->proximityPosition = 0;
total += xmlXPathCompOpEval(ctxt,&comp->steps[op->ch2]);
@@ -10631,11 +10632,11 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
* Run the evaluation with a node list made of a
* single item in the nodelocset.
*/
- ctxt->context->node = oldlocset->locTab[i]->user;
+ ctxt->context->node = (xmlNodePtr)ctxt->context->doc;
+ ctxt->context->contextSize = 1;
+ ctxt->context->proximityPosition = 1;
tmp = xmlXPathNewNodeSet(ctxt->context->node);
valuePush(ctxt, tmp);
- ctxt->context->contextSize = oldlocset->locNr;
- ctxt->context->proximityPosition = i + 1;
if (op->ch2 != -1)
total +=
@@ -10644,14 +10645,29 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
CHECK_ERROR0;
/*
- * The result of the evaluation need to be tested to
- * decided whether the filter succeeded or not
+ * The result of the evaluation needs to be tested to
+ * decide whether the filter succeeded or not
*/
res = valuePop(ctxt);
- if (xmlXPathEvaluatePredicateResult(ctxt, res)) {
- xmlXPtrLocationSetAdd(newlocset,
- xmlXPathObjectCopy
- (oldlocset->locTab[i]));
+ if (res->type == XPATH_LOCATIONSET) {
+ xmlLocationSetPtr rloc =
+ (xmlLocationSetPtr)res->user;
+ for (j=0; j<rloc->locNr; j++) {
+ range = xmlXPtrNewRange(
+ oldlocset->locTab[i]->user,
+ oldlocset->locTab[i]->index,
+ rloc->locTab[j]->user2,
+ rloc->locTab[j]->index2);
+ if (range != NULL) {
+ xmlXPtrLocationSetAdd(newlocset, range);
+ }
+ }
+ } else {
+ range = xmlXPtrNewRangeNodeObject(
+ (xmlNodePtr)oldlocset->locTab[i]->user, res);
+ if (range != NULL) {
+ xmlXPtrLocationSetAdd(newlocset,range);
+ }
}
/*
@@ -10666,7 +10682,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op)
ctxt->context->node = NULL;
}
- } else { /* Not a location set */
+ } else { /* Not a location set */
CHECK_TYPE0(XPATH_NODESET);
obj = valuePop(ctxt);
oldset = obj->nodesetval;
diff --git a/xpointer.c b/xpointer.c
index ee32e89c..adc854c1 100644
--- a/xpointer.c
+++ b/xpointer.c
@@ -124,7 +124,6 @@ xmlXPtrErr(xmlXPathParserContextPtr ctxt, int error,
* *
************************************************************************/
-xmlNodePtr xmlXPtrAdvanceNode(xmlNodePtr cur);
/**
* xmlXPtrGetArity:
* @cur: the node
@@ -549,6 +548,7 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {
return(NULL);
switch (end->type) {
case XPATH_POINT:
+ case XPATH_RANGE:
break;
case XPATH_NODESET:
/*
@@ -575,6 +575,11 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {
case XPATH_POINT:
ret->user2 = end->user;
ret->index2 = end->index;
+ break;
+ case XPATH_RANGE:
+ ret->user2 = end->user2;
+ ret->index2 = end->index2;
+ break;
case XPATH_NODESET: {
ret->user2 = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];
ret->index2 = -1;
@@ -1029,6 +1034,15 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
const xmlChar *left = CUR_PTR;
CUR_PTR = buffer;
+ /*
+ * To evaluate an xpointer scheme element (4.3) we need:
+ * context initialized to the root
+ * context position initalized to 1
+ * context size initialized to 1
+ */
+ ctxt->context->node = (xmlNodePtr)ctxt->context->doc;
+ ctxt->context->proximityPosition = 1;
+ ctxt->context->contextSize = 1;
xmlXPathEvalExpr(ctxt);
CUR_PTR=left;
} else if (xmlStrEqual(name, (xmlChar *) "element")) {