mirror of
https://github.com/postgres/postgres.git
synced 2025-06-07 11:02:12 +03:00
Free libxml2/libxslt resources in a safer order.
Mark Simonetti reported that libxslt sometimes crashes for him, and that swapping xslt_process's object-freeing calls around to do them in reverse order of creation seemed to fix it. I've not reproduced the crash, but valgrind clearly shows a reference to already-freed memory, which is consistent with the idea that shutdown of the xsltTransformContext is trying to reference the already-freed stylesheet or input document. With this patch, valgrind is no longer unhappy. I have an inquiry in to see if this is a libxslt bug or if we're just abusing the library; but even if it's a library bug, we'd want to adjust our code so it doesn't fail with unpatched libraries. Back-patch to all supported branches, because we've been doing this in the wrong(?) order for a long time.
This commit is contained in:
parent
95be343622
commit
168636a991
@ -140,10 +140,10 @@ xslt_process(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
if (xslt_sec_prefs_error)
|
if (xslt_sec_prefs_error)
|
||||||
{
|
{
|
||||||
|
xsltFreeTransformContext(xslt_ctxt);
|
||||||
|
xsltFreeSecurityPrefs(xslt_sec_prefs);
|
||||||
xsltFreeStylesheet(stylesheet);
|
xsltFreeStylesheet(stylesheet);
|
||||||
xmlFreeDoc(doctree);
|
xmlFreeDoc(doctree);
|
||||||
xsltFreeSecurityPrefs(xslt_sec_prefs);
|
|
||||||
xsltFreeTransformContext(xslt_ctxt);
|
|
||||||
xsltCleanupGlobals();
|
xsltCleanupGlobals();
|
||||||
xml_ereport(ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
|
xml_ereport(ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
|
||||||
"could not set libxslt security preferences");
|
"could not set libxslt security preferences");
|
||||||
@ -154,10 +154,10 @@ xslt_process(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
if (restree == NULL)
|
if (restree == NULL)
|
||||||
{
|
{
|
||||||
|
xsltFreeTransformContext(xslt_ctxt);
|
||||||
|
xsltFreeSecurityPrefs(xslt_sec_prefs);
|
||||||
xsltFreeStylesheet(stylesheet);
|
xsltFreeStylesheet(stylesheet);
|
||||||
xmlFreeDoc(doctree);
|
xmlFreeDoc(doctree);
|
||||||
xsltFreeSecurityPrefs(xslt_sec_prefs);
|
|
||||||
xsltFreeTransformContext(xslt_ctxt);
|
|
||||||
xsltCleanupGlobals();
|
xsltCleanupGlobals();
|
||||||
xml_ereport(ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
|
xml_ereport(ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
|
||||||
"failed to apply stylesheet");
|
"failed to apply stylesheet");
|
||||||
@ -165,11 +165,11 @@ xslt_process(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
resstat = xsltSaveResultToString(&resstr, &reslen, restree, stylesheet);
|
resstat = xsltSaveResultToString(&resstr, &reslen, restree, stylesheet);
|
||||||
|
|
||||||
xsltFreeStylesheet(stylesheet);
|
|
||||||
xmlFreeDoc(restree);
|
xmlFreeDoc(restree);
|
||||||
xmlFreeDoc(doctree);
|
|
||||||
xsltFreeSecurityPrefs(xslt_sec_prefs);
|
|
||||||
xsltFreeTransformContext(xslt_ctxt);
|
xsltFreeTransformContext(xslt_ctxt);
|
||||||
|
xsltFreeSecurityPrefs(xslt_sec_prefs);
|
||||||
|
xsltFreeStylesheet(stylesheet);
|
||||||
|
xmlFreeDoc(doctree);
|
||||||
|
|
||||||
xsltCleanupGlobals();
|
xsltCleanupGlobals();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user