[Opensrf-commits] r1269 - trunk/src/libopensrf

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Mar 9 22:58:38 EDT 2008


Author: miker
Date: 2008-03-09 22:25:39 -0400 (Sun, 09 Mar 2008)
New Revision: 1269

Modified:
   trunk/src/libopensrf/osrf_cache.c
Log:
Patch from Scott McKellar:

This patch plugs a memory leak and tweaks a couple of minor things.

1. In osrfCacheGetObject() I added the const qualifier to the "data"
variable, since we don't write through that pointer.

2. In osrfCacheGetString() I corrected an error message that claimed
to be coming from a different function.

3. In osrfCacheSetExpire() we were leaking a jsonObject allocated by
osrfCacheGetObject().  I contrived to free it.



Modified: trunk/src/libopensrf/osrf_cache.c
===================================================================
--- trunk/src/libopensrf/osrf_cache.c	2008-03-10 02:21:03 UTC (rev 1268)
+++ trunk/src/libopensrf/osrf_cache.c	2008-03-10 02:25:39 UTC (rev 1269)
@@ -53,7 +53,7 @@
 	jsonObject* obj = NULL;
 	if( key ) {
 		VA_LIST_TO_STRING(key);
-		char* data = (char*) mc_aget( _osrfCache, VA_BUF, strlen(VA_BUF) );
+		const char* data = (const char*) mc_aget( _osrfCache, VA_BUF, strlen(VA_BUF) );
 		if( data ) {
 			osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetObject(): Returning object: %s", data);
 			obj = jsonParseString( data );
@@ -68,7 +68,7 @@
 	if( key ) {
 		VA_LIST_TO_STRING(key);
 		char* data = (char*) mc_aget(_osrfCache, VA_BUF, strlen(VA_BUF) );
-		osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetObject(): Returning object: %s", data);
+		osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetString(): Returning object: %s", data);
 		if(!data) osrfLogWarning(OSRF_LOG_MARK, "No cache data exists with key %s", VA_BUF);
 		return data;
 	}
@@ -90,7 +90,9 @@
 		VA_LIST_TO_STRING(key);
 		jsonObject* o = osrfCacheGetObject( VA_BUF );
 		//osrfCacheRemove(VA_BUF);
-		return osrfCachePutObject( VA_BUF, o, seconds );
+		int rc = osrfCachePutObject( VA_BUF, o, seconds );
+		jsonObjectFree(o);
+		return rc;
 	}
 	return -1;
 }



More information about the opensrf-commits mailing list