aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-03-03 19:10:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-03-03 19:10:52 +0000
commita15fa97a18642db487b1176384e27a281976c950 (patch)
tree61dab1d7a358f5dab44f4b757adc8c0a5b2ad0de
parent727af2a58a7b07ff4b7752ba8d84507d300e49f6 (diff)
downloadpostgresql-a15fa97a18642db487b1176384e27a281976c950.tar.gz
postgresql-a15fa97a18642db487b1176384e27a281976c950.zip
Make contrib/xml2 use core xml.c's error handler, when available (that is,
in versions >= 8.3). The core code is more robust and efficient than what was there before, and this also reduces risks involved in swapping different libxml error handler settings. Before 8.3, there is still some risk of problems if add-on modules such as Perl invoke libxml without setting their own error handler. Given the lack of reports I'm not sure there's a risk in practice, so I didn't take the step of actually duplicating the core code into older contrib/xml2 branches. Instead I just tweaked the existing code to ensure it didn't leave a dangling pointer to short-lived memory when throwing an error.
-rw-r--r--contrib/xml2/xpath.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c
index 25cc7f9377b..51069adfc52 100644
--- a/contrib/xml2/xpath.c
+++ b/contrib/xml2/xpath.c
@@ -100,9 +100,20 @@ elog_error(const char *explain, bool force)
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
errmsg("%s", explain)));
else
+ {
+ /*
+ * Ensure pgxml_errorMsg is reset to null before we give up
+ * control. This provides some protection against crashes if
+ * pgxml_errorHandler is invoked again later, perhaps as a
+ * result of other modules' use of libxml.
+ */
+ char *msg = pgxml_errorMsg;
+
+ pgxml_errorMsg = NULL;
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
- errmsg("%s: %s", explain, pgxml_errorMsg)));
+ errmsg("%s: %s", explain, msg)));
+ }
}
}