Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2012-06-05 00:12:50 +0000
committerTom Lane2012-06-05 00:12:50 +0000
commitd9b31e4859df5325b7d3d2cc94b0e907f1cf1d3e (patch)
tree05c54b300e09e0e05f12ce502c8e33be10351f6e /contrib/xml2/xslt_proc.c
parentd73b7f973db5ec7e44813141741d3e0d318eef69 (diff)
Fix some more bugs in contrib/xml2's xslt_process().
It failed to check for error return from xsltApplyStylesheet(), as reported by Peter Gagarinov. (So far as I can tell, libxslt provides no convenient way to get a useful error message in failure cases. There might be some inconvenient way, but considering that this code is deprecated it's hard to get enthusiastic about putting lots of work into it. So I just made it say "failed to apply stylesheet", in line with the existing error checks.) While looking at the code I also noticed that the string returned by xsltSaveResultToString was never freed, resulting in a session-lifespan memory leak. Back-patch to all supported versions.
Diffstat (limited to 'contrib/xml2/xslt_proc.c')
-rw-r--r--contrib/xml2/xslt_proc.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/contrib/xml2/xslt_proc.c b/contrib/xml2/xslt_proc.c
index a8e481a3ce8..ba1171a041f 100644
--- a/contrib/xml2/xslt_proc.c
+++ b/contrib/xml2/xslt_proc.c
@@ -54,6 +54,7 @@ xslt_process(PG_FUNCTION_ARGS)
text *doct = PG_GETARG_TEXT_P(0);
text *ssheet = PG_GETARG_TEXT_P(1);
+ text *result;
text *paramstr;
const char **params;
PgXmlErrorContext *xmlerrcxt;
@@ -112,6 +113,11 @@ xslt_process(PG_FUNCTION_ARGS)
"failed to parse stylesheet");
restree = xsltApplyStylesheet(stylesheet, doctree, params);
+
+ if (restree == NULL)
+ xml_ereport(xmlerrcxt, ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
+ "failed to apply stylesheet");
+
resstat = xsltSaveResultToString(&resstr, &reslen, restree, stylesheet);
}
PG_CATCH();
@@ -137,10 +143,16 @@ xslt_process(PG_FUNCTION_ARGS)
pg_xml_done(xmlerrcxt, false);
+ /* XXX this is pretty dubious, really ought to throw error instead */
if (resstat < 0)
PG_RETURN_NULL();
- PG_RETURN_TEXT_P(cstring_to_text_with_len((char *) resstr, reslen));
+ result = cstring_to_text_with_len((char *) resstr, reslen);
+
+ if (resstr)
+ xmlFree(resstr);
+
+ PG_RETURN_TEXT_P(result);
#else /* !USE_LIBXSLT */
ereport(ERROR,