From e3d6b4c9104094ba80a9479ec8a41d4b30def832 Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 10 Mar 2008 04:30:59 +0000 Subject: [PATCH] Patch from Scott McKellar: 1. The functions _rest_xml_output and _escape_xml are now static, and a couple of their parameters are now const. 2. In json_string_to_xml() we were leaking res_xml in the case of an early return. I moved the early return out of the way. 3. In _rest_xml_output() we were leaking tag in the case of an early return. I plugged that leak. 4. In a couple of spots I replaced buffer_data() with buffer_release(), and eliminated two intermediate variables that are no longer needed. git-svn-id: svn://svn.open-ils.org/ILS/trunk@8953 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/apachemods/json_xml.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/apachemods/json_xml.c b/Open-ILS/src/apachemods/json_xml.c index e7c11b6d16..8b2195137b 100644 --- a/Open-ILS/src/apachemods/json_xml.c +++ b/Open-ILS/src/apachemods/json_xml.c @@ -1,21 +1,20 @@ #include "json_xml.h" #include "fieldmapper_lookup.h" -void _rest_xml_output(growing_buffer*, jsonObject*, char*, int, int); -char* _escape_xml (char*); +static void _rest_xml_output(growing_buffer*, const jsonObject*, char*, int, int); +static char* _escape_xml (const char*); char* json_string_to_xml(char* content) { jsonObject * obj; growing_buffer * res_xml; - char * output; int i; obj = json_parse_string( content ); - res_xml = buffer_init(1024); if (!obj) return NULL; + res_xml = buffer_init(1024); buffer_add(res_xml, ""); if(obj->type == JSON_ARRAY ) { @@ -28,15 +27,11 @@ char* json_string_to_xml(char* content) { buffer_add(res_xml, ""); - output = buffer_data(res_xml); - buffer_free(res_xml); jsonObjectFree(obj); - - return output; + return buffer_release(res_xml); } -char* _escape_xml (char* text) { - char* out; +char* _escape_xml (const char* text) { growing_buffer* b = buffer_init(256); int len = strlen(text); int i; @@ -50,12 +45,11 @@ char* _escape_xml (char* text) { else buffer_add_char(b,text[i]); } - out = buffer_data(b); - buffer_free(b); - return out; + return buffer_release(b); } -void _rest_xml_output(growing_buffer* buf, jsonObject* obj, char * obj_class, int arr_index, int notag) { +static void _rest_xml_output(growing_buffer* buf, const jsonObject* obj, + char * obj_class, int arr_index, int notag) { char * tag; int i; @@ -77,6 +71,7 @@ void _rest_xml_output(growing_buffer* buf, jsonObject* obj, char * obj_class, in if(obj->classname) { if(obj->type == JSON_NULL) { buffer_fadd(buf,"<%s>", tag, obj->classname, tag); + free(tag); return; } else { buffer_fadd(buf,"<%s>", tag, obj->classname); -- 2.43.2