From 1eadd8bd792b3a1d9a831580be833e0c6ccee354 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 12 Jun 2007 01:30:49 +0000 Subject: [PATCH] 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 --- src/libstack/osrfConfig.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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; } -- 2.43.2