Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8948ee3

Browse files
committed
Fix multiple memory leaks in xml_out(). Per report from Matt Magoffin.
1 parent 1cd9356 commit 8948ee3

File tree

1 file changed

+8
-10
lines changed
  • src/backend/utils/adt

1 file changed

+8
-10
lines changed

src/backend/utils/adt/xml.c

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.76 2008/08/25 22:42:34 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.77 2008/09/16 00:49:41 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -208,22 +208,16 @@ xml_in(PG_FUNCTION_ARGS)
208208
static char *
209209
xml_out_internal(xmltype *x, pg_enc target_encoding)
210210
{
211-
char *str;
212-
size_t len;
211+
char *str = text_to_cstring((text *) x);
213212

214213
#ifdef USE_LIBXML
214+
size_t len = strlen(str);
215215
xmlChar *version;
216-
xmlChar *encoding;
217216
int standalone;
218217
int res_code;
219-
#endif
220-
221-
str = text_to_cstring((text *) x);
222-
len = strlen(str);
223218

224-
#ifdef USE_LIBXML
225219
if ((res_code = parse_xml_decl((xmlChar *) str,
226-
&len, &version, &encoding, &standalone)) == 0)
220+
&len, &version, NULL, &standalone)) == 0)
227221
{
228222
StringInfoData buf;
229223

@@ -241,6 +235,10 @@ xml_out_internal(xmltype *x, pg_enc target_encoding)
241235
}
242236
appendStringInfoString(&buf, str + len);
243237

238+
if (version)
239+
xmlFree(version);
240+
pfree(str);
241+
244242
return buf.data;
245243
}
246244

0 commit comments

Comments
 (0)