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
775775if (uri )
776776xmlFreeURI (uri );
777+ uri = NULL ;
777778#endif
778779if (dtd )
779780xmlFreeDtd (dtd );
781+ dtd = NULL ;
780782if (doc )
781783xmlFreeDoc (doc );
784+ doc = NULL ;
782785if (ctxt )
783786xmlFreeParserCtxt (ctxt );
787+ ctxt = NULL ;
784788xmlCleanupParser ();
785789}
786790PG_CATCH ();
@@ -1163,13 +1167,13 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, xml
11631167
11641168if (ctxt )
11651169xmlFreeParserCtxt (ctxt );
1170+ ctxt = NULL ;
11661171xmlCleanupParser ();
11671172}
11681173PG_CATCH ();
11691174{
11701175if (doc )
11711176xmlFreeDoc (doc );
1172- doc = NULL ;
11731177if (ctxt )
11741178xmlFreeParserCtxt (ctxt );
11751179xmlCleanupParser ();
@@ -3203,10 +3207,12 @@ xpath(PG_FUNCTION_ARGS)
32033207"invalid XPath expression" );/* TODO: show proper XPath error details */
32043208
32053209xpathobj = xmlXPathCompiledEval (xpathcomp ,xpathctx );
3206- xmlXPathFreeCompExpr (xpathcomp );
32073210if (xpathobj == NULL )
32083211ereport (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 */
32113217if (xpathobj -> nodesetval == NULL )
32123218res_nitems = 0 ;
@@ -3225,9 +3231,13 @@ xpath(PG_FUNCTION_ARGS)
32253231}
32263232
32273233xmlXPathFreeObject (xpathobj );
3234+ xpathobj = NULL ;
32283235xmlXPathFreeContext (xpathctx );
3229- xmlFreeParserCtxt ( ctxt ) ;
3236+ xpathctx = NULL ;
32303237xmlFreeDoc (doc );
3238+ doc = NULL ;
3239+ xmlFreeParserCtxt (ctxt );
3240+ ctxt = NULL ;
32313241xmlCleanupParser ();
32323242}
32333243PG_CATCH ();