Fix multiple memory leaks in xml_out(). Per report from Matt Magoffin.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 Sep 2008 00:49:49 +0000 (00:49 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 Sep 2008 00:49:49 +0000 (00:49 +0000)
src/backend/utils/adt/xml.c

index 190cdf13976fd067f80fa4f99ec7aba77c6e16a0..0e5b325d0744fdd57cd4e483993175cafb887a26 100644 (file)
@@ -208,22 +208,16 @@ xml_in(PG_FUNCTION_ARGS)
 static char *
 xml_out_internal(xmltype *x, pg_enc target_encoding)
 {
-       char       *str;
-       size_t          len;
+       char       *str = text_to_cstring((text *) x);
 
 #ifdef USE_LIBXML
+       size_t          len = strlen(str);
        xmlChar    *version;
-       xmlChar    *encoding;
        int                     standalone;
        int                     res_code;
-#endif
-
-       str = text_to_cstring((text *) x);
-       len = strlen(str);
 
-#ifdef USE_LIBXML
        if ((res_code = parse_xml_decl((xmlChar *) str,
-                                                          &len, &version, &encoding, &standalone)) == 0)
+                                                                  &len, &version, NULL, &standalone)) == 0)
        {
                StringInfoData buf;
 
@@ -241,6 +235,10 @@ xml_out_internal(xmltype *x, pg_enc target_encoding)
                }
                appendStringInfoString(&buf, str + len);
 
+               if (version)
+                       xmlFree(version);
+               pfree(str);
+
                return buf.data;
        }