[Opensrf-commits] r1271 - trunk/src/router

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Mar 9 23:35:06 EDT 2008


Author: miker
Date: 2008-03-09 23:02:07 -0400 (Sun, 09 Mar 2008)
New Revision: 1271

Modified:
   trunk/src/router/osrf_router.c
Log:
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)".



Modified: trunk/src/router/osrf_router.c
===================================================================
--- trunk/src/router/osrf_router.c	2008-03-10 02:54:12 UTC (rev 1270)
+++ trunk/src/router/osrf_router.c	2008-03-10 03:02:07 UTC (rev 1271)
@@ -521,6 +521,7 @@
 void osrfRouterFree( osrfRouter* router ) {
 	if(!router) return;
 
+	osrfHashFree(router->classes);
 	free(router->domain);		
 	free(router->name);
 	free(router->resource);
@@ -670,7 +671,7 @@
 	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 @@
 		if (!classname)
 			return -1;
 
-		jresponse = jsonParseString("{}");
+		jresponse = jsonNewObjectType(JSON_HASH);
 		class = osrfHashGet(router->classes, classname);
 		free(classname);
 
@@ -725,12 +726,12 @@
 
 		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 @@
 		osrfRouterClass* class;
 		osrfRouterNode* node;
 		int count;
-		jresponse = jsonParseString("{}");
+		jresponse = jsonNewObjectType(JSON_HASH);
 
 		osrfHashIterator* class_itr = osrfNewHashIterator(router->classes);
 		while( (class = osrfHashIteratorNext(class_itr)) ) {



More information about the opensrf-commits mailing list