From: miker Date: Tue, 12 Jun 2007 01:30:49 +0000 (+0000) Subject: Patch from Scott McKellar; rearranges some logic to avoid a potential memory leak X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1eadd8bd792b3a1d9a831580be833e0c6ccee354;p=opensrf%2Fbjwebb.git Patch from Scott McKellar; rearranges some logic to avoid a potential memory leak git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@943 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/libstack/osrfConfig.c b/src/libstack/osrfConfig.c index a852625..7d03521 100644 --- a/src/libstack/osrfConfig.c +++ b/src/libstack/osrfConfig.c @@ -41,24 +41,33 @@ void osrfConfigReplaceConfig(osrfConfig* cfg, const jsonObject* obj) { osrfConfig* osrfConfigInit(char* configFile, char* configContext) { if(!configFile) return NULL; - osrfConfig* cfg = safe_malloc(sizeof(osrfConfig)); - if(configContext) cfg->configContext = strdup(configContext); - else cfg->configContext = NULL; - + // Load XML from the configuration file + xmlDocPtr doc = xmlParseFile(configFile); if(!doc) { osrfLogWarning( OSRF_LOG_MARK, "Unable to parse XML config file %s", configFile); return NULL; } - cfg->config = xmlDocToJSON(doc); + // Translate it into a jsonObject + + jsonObject* json_config = xmlDocToJSON(doc); xmlFreeDoc(doc); - if(!cfg->config) { + if(!json_config ) { osrfLogWarning( OSRF_LOG_MARK, "xmlDocToJSON failed for config %s", configFile); return NULL; } + // Build an osrfConfig and return it by pointer + + osrfConfig* cfg = safe_malloc(sizeof(osrfConfig)); + + if(configContext) cfg->configContext = strdup(configContext); + else cfg->configContext = NULL; + + cfg->config = json_config; + return cfg; }