From 217a59397e584acac57d18f436771532b0685d8d Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 7 Jan 2008 02:04:54 +0000 Subject: [PATCH] JSON to XML patches from Scott McKellar: Guard against multiple #inclusions. Plug a potential memory leak in the jsonObjectToXML function. If the input parameter was NULL we would fail to free the growing_buffer we had just allocated. I rearranged it to check for NULL before allocating the growing_buffer. Also: I added the static qualifier to the _escape_xml function, to match the declaration at the top of the file. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1208 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/osrf_json_xml.h | 4 ++++ src/libopensrf/osrf_json_xml.c | 8 +++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/opensrf/osrf_json_xml.h b/include/opensrf/osrf_json_xml.h index 2381da0..ce06817 100644 --- a/include/opensrf/osrf_json_xml.h +++ b/include/opensrf/osrf_json_xml.h @@ -1,3 +1,6 @@ +#ifndef OSRF_JSON_XML_H +#define OSRF_JSON_XML_H + #ifdef OSRF_JSON_ENABLE_XML_UTILS #include @@ -24,3 +27,4 @@ char* jsonObjectToXML( const jsonObject*); jsonObject* jsonXMLToJSONObject(const char* xml); #endif +#endif diff --git a/src/libopensrf/osrf_json_xml.c b/src/libopensrf/osrf_json_xml.c index ecca429..68a0796 100644 --- a/src/libopensrf/osrf_json_xml.c +++ b/src/libopensrf/osrf_json_xml.c @@ -233,13 +233,11 @@ static int _recurse_jsonObjectToXML(const jsonObject*, growing_buffer*); char* jsonObjectToXML(const jsonObject* obj) { - growing_buffer * res_xml; - - res_xml = buffer_init(1024); - if (!obj) return strdup(""); + growing_buffer * res_xml = buffer_init(1024); + _recurse_jsonObjectToXML( obj, res_xml ); return buffer_release(res_xml); @@ -335,7 +333,7 @@ int _recurse_jsonObjectToXML(const jsonObject* obj, growing_buffer* res_xml) { return 1; } -char* _escape_xml (const char* text) { +static char* _escape_xml (const char* text) { growing_buffer* b = buffer_init(256); int len = strlen(text); int i; -- 2.43.2