From: miker Date: Mon, 10 Mar 2008 03:02:07 +0000 (+0000) Subject: Patch from Scott McKellar: X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=107df78b51355f22a421cb10fcc93bbe00aeb840;p=working%2FOpenSRF.git Patch from Scott McKellar: This patch plugs a memory leak that I somehow missed earlier, and adds a few performance tweaks. 1. In osrfRouterFree() I added a line to free the osrfHash to which the classes member points. 2. I replaced an occurrence of "jsonParseString("[]")" with "jsonNewObjectType(JSON_ARRAY)", a call that produces the same result with a lot less overhead. 3. For similar reasons I replaced several occurrences of "jsonParseString("{}")" with "jsonNewObjectType(JSON_HASH)". git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1271 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/router/osrf_router.c b/src/router/osrf_router.c index 90be999..5a50041 100644 --- a/src/router/osrf_router.c +++ b/src/router/osrf_router.c @@ -521,6 +521,7 @@ static void osrfRouterNodeFree( char* remoteId, void* n ) { void osrfRouterFree( osrfRouter* router ) { if(!router) return; + osrfHashFree(router->classes); free(router->domain); free(router->name); free(router->resource); @@ -670,7 +671,7 @@ static int osrfRouterProcessAppRequest( osrfRouter* router, transport_message* m if(!strcmp( omsg->method_name, ROUTER_REQUEST_CLASS_LIST )) { int i; - jresponse = jsonParseString("[]"); + jresponse = jsonNewObjectType(JSON_ARRAY); osrfStringArray* keys = osrfHashKeys( router->classes ); for( i = 0; i != keys->size; i++ ) @@ -711,7 +712,7 @@ static int osrfRouterProcessAppRequest( osrfRouter* router, transport_message* m if (!classname) return -1; - jresponse = jsonParseString("{}"); + jresponse = jsonNewObjectType(JSON_HASH); class = osrfHashGet(router->classes, classname); free(classname); @@ -725,12 +726,12 @@ static int osrfRouterProcessAppRequest( osrfRouter* router, transport_message* m osrfRouterClass* class; osrfRouterNode* node; - jresponse = jsonParseString("{}"); + jresponse = jsonNewObjectType(JSON_HASH); osrfHashIterator* class_itr = osrfNewHashIterator(router->classes); while( (class = osrfHashIteratorNext(class_itr)) ) { - jsonObject* class_res = jsonParseString("{}"); + jsonObject* class_res = jsonNewObjectType(JSON_HASH); char* classname = class_itr->current; osrfHashIterator* node_itr = osrfNewHashIterator(class->nodes); @@ -749,7 +750,7 @@ static int osrfRouterProcessAppRequest( osrfRouter* router, transport_message* m osrfRouterClass* class; osrfRouterNode* node; int count; - jresponse = jsonParseString("{}"); + jresponse = jsonNewObjectType(JSON_HASH); osrfHashIterator* class_itr = osrfNewHashIterator(router->classes); while( (class = osrfHashIteratorNext(class_itr)) ) {