From 56df909db6a14f2e1ab086f389e4ebb2d1254989 Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 3 Aug 2005 15:23:24 +0000 Subject: [PATCH] staving off memory leaks git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@457 9efc2488-bf62-4759-914b-345cdb29e865 --- src/gateway/fieldmapper-c-xml-out.pl | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/gateway/fieldmapper-c-xml-out.pl b/src/gateway/fieldmapper-c-xml-out.pl index 6724ff5..09cfe9d 100755 --- a/src/gateway/fieldmapper-c-xml-out.pl +++ b/src/gateway/fieldmapper-c-xml-out.pl @@ -41,6 +41,7 @@ print SOURCE < +#include #include "objson/object.h" #include "objson/json_parser.h" #include "opensrf/utils.h" @@ -83,16 +84,18 @@ char* _escape_xml (char* text) { int i; for (i = 0; i < len; i++) { if (text[i] == '&') - buffer_add(b,strdup("&")); + buffer_add(b,"&"); else if (text[i] == '<') - buffer_add(b,strdup("<")); + buffer_add(b,"<"); else if (text[i] == '>') - buffer_add(b,strdup(">")); + buffer_add(b,">"); else buffer_add_char(b,text[i]); } out = buffer_data(b); buffer_free(b); + fprintf(stderr," XXX Escaped string: %s\\n", out); + fflush(stderr); return out; } @@ -137,11 +140,13 @@ void _rest_xml_output(growing_buffer* buf, object* obj, char * fm_class, int fm_ } else if (obj->is_string) { if (notag) { - //buffer_add(buf,_escape_xml(obj->string_data)); - buffer_add(buf,obj->string_data); + char * t = _escape_xml(obj->string_data); + buffer_add(buf,t); + free(t); } else { - //buffer_fadd(buf,"<%s>%s",tag,_escape_xml(obj->string_data),tag); - buffer_fadd(buf,"<%s>%s",tag,obj->string_data,tag); + char * t = _escape_xml(obj->string_data); + buffer_fadd(buf,"<%s>%s",tag,t,tag); + free(t); } } else if(obj->is_number) { @@ -216,6 +221,8 @@ void _rest_xml_output(growing_buffer* buf, object* obj, char * fm_class, int fm_ if (obj->classname) buffer_fadd(buf,"",tag); + + free(tag); } char * _lookup_fm_field(char * class, int pos) { -- 2.11.0