@@ -803,12 +803,10 @@ xpath_table(PG_FUNCTION_ARGS)
803
803
xmlXPathCompExprPtr comppath ;
804
804
805
805
/* Extract the row data as C Strings */
806
-
807
806
spi_tuple = tuptable -> vals [i ];
808
807
pkey = SPI_getvalue (spi_tuple ,spi_tupdesc ,1 );
809
808
xmldoc = SPI_getvalue (spi_tuple ,spi_tupdesc ,2 );
810
809
811
-
812
810
/*
813
811
* Clear the values array, so that not-well-formed documents return
814
812
* NULL in all columns.
@@ -822,11 +820,14 @@ xpath_table(PG_FUNCTION_ARGS)
822
820
values [0 ]= pkey ;
823
821
824
822
/* Parse the document */
825
- doctree = xmlParseMemory (xmldoc ,strlen (xmldoc ));
823
+ if (xmldoc )
824
+ doctree = xmlParseMemory (xmldoc ,strlen (xmldoc ));
825
+ else /* treat NULL as not well-formed */
826
+ doctree = NULL ;
826
827
827
828
if (doctree == NULL )
828
- {/* not well-formed, so output all-NULL tuple */
829
-
829
+ {
830
+ /* not well-formed, so output all-NULL tuple */
830
831
ret_tuple = BuildTupleFromCStrings (attinmeta ,values );
831
832
oldcontext = MemoryContextSwitchTo (per_query_ctx );
832
833
tuplestore_puttuple (tupstore ,ret_tuple );
@@ -918,8 +919,10 @@ xpath_table(PG_FUNCTION_ARGS)
918
919
919
920
xmlFreeDoc (doctree );
920
921
921
- pfree (pkey );
922
- pfree (xmldoc );
922
+ if (pkey )
923
+ pfree (pkey );
924
+ if (xmldoc )
925
+ pfree (xmldoc );
923
926
}
924
927
925
928
xmlCleanupParser ();