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)
208208static char *
209209xml_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 );
215215xmlChar * version ;
216- xmlChar * encoding ;
217216int standalone ;
218217int res_code ;
219- #endif
220-
221- str = text_to_cstring ((text * )x );
222- len = strlen (str );
223218
224- #ifdef USE_LIBXML
225219if ((res_code = parse_xml_decl ((xmlChar * )str ,
226- & len ,& version ,& encoding ,& standalone ))== 0 )
220+ & len ,& version ,NULL ,& standalone ))== 0 )
227221{
228222StringInfoData buf ;
229223
@@ -241,6 +235,10 @@ xml_out_internal(xmltype *x, pg_enc target_encoding)
241235}
242236appendStringInfoString (& buf ,str + len );
243237
238+ if (version )
239+ xmlFree (version );
240+ pfree (str );
241+
244242return buf .data ;
245243}
246244