Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ff1de5c

Browse files
committed
Guard against possible double free during error escape from XML
functions. Patch for the reported issue from Kris Jurka, some other potential trouble spots plugged by Tom.
1 parent 8468146 commit ff1de5c

File tree

1 file changed

+14
-4
lines changed
  • src/backend/utils/adt

1 file changed

+14
-4
lines changed

src/backend/utils/adt/xml.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.48 2007/10/13 20:18:41 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.49 2007/10/13 20:46:47 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -774,13 +774,17 @@ xmlvalidate(PG_FUNCTION_ARGS)
774774
#if 0
775775
if (uri)
776776
xmlFreeURI(uri);
777+
uri = NULL;
777778
#endif
778779
if (dtd)
779780
xmlFreeDtd(dtd);
781+
dtd = NULL;
780782
if (doc)
781783
xmlFreeDoc(doc);
784+
doc = NULL;
782785
if (ctxt)
783786
xmlFreeParserCtxt(ctxt);
787+
ctxt = NULL;
784788
xmlCleanupParser();
785789
}
786790
PG_CATCH();
@@ -1163,13 +1167,13 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, xml
11631167

11641168
if (ctxt)
11651169
xmlFreeParserCtxt(ctxt);
1170+
ctxt = NULL;
11661171
xmlCleanupParser();
11671172
}
11681173
PG_CATCH();
11691174
{
11701175
if (doc)
11711176
xmlFreeDoc(doc);
1172-
doc = NULL;
11731177
if (ctxt)
11741178
xmlFreeParserCtxt(ctxt);
11751179
xmlCleanupParser();
@@ -3203,10 +3207,12 @@ xpath(PG_FUNCTION_ARGS)
32033207
"invalid XPath expression"); /* TODO: show proper XPath error details */
32043208

32053209
xpathobj = xmlXPathCompiledEval(xpathcomp, xpathctx);
3206-
xmlXPathFreeCompExpr(xpathcomp);
32073210
if (xpathobj == NULL)
32083211
ereport(ERROR, (errmsg("could not create XPath object"))); /* TODO: reason? */
32093212

3213+
xmlXPathFreeCompExpr(xpathcomp);
3214+
xpathcomp = NULL;
3215+
32103216
/* return empty array in cases when nothing is found */
32113217
if (xpathobj->nodesetval == NULL)
32123218
res_nitems = 0;
@@ -3225,9 +3231,13 @@ xpath(PG_FUNCTION_ARGS)
32253231
}
32263232

32273233
xmlXPathFreeObject(xpathobj);
3234+
xpathobj = NULL;
32283235
xmlXPathFreeContext(xpathctx);
3229-
xmlFreeParserCtxt(ctxt);
3236+
xpathctx = NULL;
32303237
xmlFreeDoc(doc);
3238+
doc = NULL;
3239+
xmlFreeParserCtxt(ctxt);
3240+
ctxt = NULL;
32313241
xmlCleanupParser();
32323242
}
32333243
PG_CATCH();

0 commit comments

Comments
 (0)