diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index fca92e867d08cbdc1cce73037a83622d0f928571..18f209489eae8f9ea35925ed446ee47fc3918d9f 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.90 2009/06/09 22:00:57 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.91 2009/06/10 03:44:35 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1293,7 +1293,9 @@ xml_repalloc(void *ptr, size_t size)
 static void
 xml_pfree(void *ptr)
 {
-	pfree(ptr);
+	/* At least some parts of libxml assume xmlFree(NULL) is allowed */
+	if (ptr)
+		pfree(ptr);
 }