diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-26 01:19:23 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-26 01:19:23 +0000 |
commit | 207f4699123fbf10fc5da9b422618e00e107eca1 (patch) | |
tree | d8b4ce7c1e0b6f9254f6d9ee2b0a82a6585bb0e3 /contrib/xml2/xpath.c | |
parent | 1b304e8491771bcb2d0c2b05c931d82c32045a92 (diff) |
Fix core dump in contrib/xml2's xpath_table() when the input query returns
a NULL value. Per bug #4058.
Diffstat (limited to 'contrib/xml2/xpath.c')
-rw-r--r-- | contrib/xml2/xpath.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c index b4b06a039d7..14f49d53f3f 100644 --- a/contrib/xml2/xpath.c +++ b/contrib/xml2/xpath.c @@ -806,12 +806,10 @@ xpath_table(PG_FUNCTION_ARGS) xmlXPathCompExprPtr comppath; /* Extract the row data as C Strings */ - spi_tuple = tuptable->vals[i]; pkey = SPI_getvalue(spi_tuple, spi_tupdesc, 1); xmldoc = SPI_getvalue(spi_tuple, spi_tupdesc, 2); - /* * Clear the values array, so that not-well-formed documents return * NULL in all columns. @@ -825,11 +823,14 @@ xpath_table(PG_FUNCTION_ARGS) values[0] = pkey; /* Parse the document */ - doctree = xmlParseMemory(xmldoc, strlen(xmldoc)); + if (xmldoc) + doctree = xmlParseMemory(xmldoc, strlen(xmldoc)); + else /* treat NULL as not well-formed */ + doctree = NULL; if (doctree == NULL) - { /* not well-formed, so output all-NULL tuple */ - + { + /* not well-formed, so output all-NULL tuple */ ret_tuple = BuildTupleFromCStrings(attinmeta, values); oldcontext = MemoryContextSwitchTo(per_query_ctx); tuplestore_puttuple(tupstore, ret_tuple); @@ -921,8 +922,10 @@ xpath_table(PG_FUNCTION_ARGS) xmlFreeDoc(doctree); - pfree(pkey); - pfree(xmldoc); + if (pkey) + pfree(pkey); + if (xmldoc) + pfree(xmldoc); } xmlCleanupParser(); |