[Opensrf-commits] r1208 - in trunk: include/opensrf src/libopensrf

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Jan 6 21:29:07 EST 2008


Author: miker
Date: 2008-01-06 21:04:54 -0500 (Sun, 06 Jan 2008)
New Revision: 1208

Modified:
   trunk/include/opensrf/osrf_json_xml.h
   trunk/src/libopensrf/osrf_json_xml.c
Log:
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.



Modified: trunk/include/opensrf/osrf_json_xml.h
===================================================================
--- trunk/include/opensrf/osrf_json_xml.h	2008-01-07 02:00:25 UTC (rev 1207)
+++ trunk/include/opensrf/osrf_json_xml.h	2008-01-07 02:04:54 UTC (rev 1208)
@@ -1,3 +1,6 @@
+#ifndef OSRF_JSON_XML_H
+#define OSRF_JSON_XML_H
+
 #ifdef OSRF_JSON_ENABLE_XML_UTILS
 
 #include <stdio.h>
@@ -24,3 +27,4 @@
 jsonObject* jsonXMLToJSONObject(const char* xml);
 
 #endif
+#endif

Modified: trunk/src/libopensrf/osrf_json_xml.c
===================================================================
--- trunk/src/libopensrf/osrf_json_xml.c	2008-01-07 02:00:25 UTC (rev 1207)
+++ trunk/src/libopensrf/osrf_json_xml.c	2008-01-07 02:04:54 UTC (rev 1208)
@@ -233,13 +233,11 @@
 
 char* jsonObjectToXML(const jsonObject* obj) {
 
-	growing_buffer * res_xml;
-
-	res_xml = buffer_init(1024);
-
 	if (!obj)
 		return strdup("<null/>");
 	
+	growing_buffer * res_xml = buffer_init(1024);
+
 	_recurse_jsonObjectToXML( obj, res_xml );
 	return buffer_release(res_xml);
 
@@ -335,7 +333,7 @@
 	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;



More information about the opensrf-commits mailing list