Patch from Scott McKellar:
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 31 Jan 2008 19:53:27 +0000 (19:53 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 31 Jan 2008 19:53:27 +0000 (19:53 +0000)
1. In oilsInitIDL: I added the const qualifier to the input parameter.
This change involved some juggling of a couple of extra variables.

2. Also in oilsInitIDL: I plugged a potential memory leak related to
an early return.

3. In oilsUtilsFetchUserByBarcode we create a jsonObject named
"card" but we weren't freeing it.  Now we free it.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@8551 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/c-apps/oils_utils.c

index db25e42..6743b52 100644 (file)
@@ -1,27 +1,32 @@
 #include "openils/oils_utils.h"
 #include "openils/oils_idl.h"
 
-osrfHash* oilsInitIDL(char* idl_filename) {
+osrfHash* oilsInitIDL(const char* idl_filename) {
 
-    int freeme = 0;
-    if(!idl_filename) {
-           idl_filename = osrf_settings_host_value("/IDL");
-        freeme = 1;
-    }
+       char* freeable_filename = NULL;
+       const char* filename;
 
-       if (!idl_filename) {
+       if(idl_filename)
+               filename = idl_filename;
+       else {
+               freeable_filename = osrf_settings_host_value("/IDL");
+               filename = freeable_filename;
+       }
+
+       if (!filename) {
                osrfLogError(OSRF_LOG_MARK, "No settings config for '/IDL'");
                return NULL;
        }
 
-    osrfLogInfo(OSRF_LOG_MARK, "Parsing IDL %s", idl_filename);
+       osrfLogInfo(OSRF_LOG_MARK, "Parsing IDL %s", filename);
 
-       if (!oilsIDLInit( idl_filename )) {
-               osrfLogError(OSRF_LOG_MARK, "Problem loading IDL file [%s]!", idl_filename);
+       if (!oilsIDLInit( filename )) {
+               osrfLogError(OSRF_LOG_MARK, "Problem loading IDL file [%s]!", filename);
+               if(freeable_filename) free(freeable_filename);
                return NULL;
        }
 
-    if(freeme) free(idl_filename);
+       if(freeable_filename) free(freeable_filename);
        return oilsIDL();
 }
 
@@ -143,6 +148,7 @@ jsonObject* oilsUtilsFetchUserByBarcode(const char* barcode) {
        if(!card) { jsonObjectFree(params); return NULL; }
 
        char* usr = oilsFMGetString(card, "usr");
+       jsonObjectFree(card);
        if(!usr) return NULL;
        double iusr = strtod(usr, NULL);
        free(usr);