Patch from Scott McKellar:
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 10 Mar 2008 04:30:59 +0000 (04:30 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 10 Mar 2008 04:30:59 +0000 (04:30 +0000)
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

index e7c11b6..8b21951 100644 (file)
@@ -1,21 +1,20 @@
 #include "json_xml.h"
 #include "fieldmapper_lookup.h"
 
 #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* json_string_to_xml(char* content) {
        jsonObject * obj;
        growing_buffer * res_xml;
-       char * output;
        int i;
 
        obj = json_parse_string( content );
        int i;
 
        obj = json_parse_string( content );
-       res_xml = buffer_init(1024);
 
        if (!obj)
                return NULL;
        
 
        if (!obj)
                return NULL;
        
+       res_xml = buffer_init(1024);
        buffer_add(res_xml, "<response>");
 
        if(obj->type == JSON_ARRAY ) {
        buffer_add(res_xml, "<response>");
 
        if(obj->type == JSON_ARRAY ) {
@@ -28,15 +27,11 @@ char* json_string_to_xml(char* content) {
 
        buffer_add(res_xml, "</response>");
 
 
        buffer_add(res_xml, "</response>");
 
-       output = buffer_data(res_xml);
-       buffer_free(res_xml);
        jsonObjectFree(obj);
        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;
        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]);
        }
                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;
        
        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><Object class_hint=\"%s\"/></%s>", tag, obj->classname, tag);
    if(obj->classname) {
        if(obj->type == JSON_NULL) {
                        buffer_fadd(buf,"<%s><Object class_hint=\"%s\"/></%s>", tag, obj->classname, tag);
+                       free(tag);
                        return;
                } else {
                        buffer_fadd(buf,"<%s><Object class_hint=\"%s\">", tag, obj->classname);
                        return;
                } else {
                        buffer_fadd(buf,"<%s><Object class_hint=\"%s\">", tag, obj->classname);