From 6a7a11135d3a6bc875c118dc63a43c2c1e87e3dd Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 10 Mar 2008 02:25:39 +0000 Subject: [PATCH 1/1] 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. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1269 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libopensrf/osrf_cache.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libopensrf/osrf_cache.c b/src/libopensrf/osrf_cache.c index 16c6a54..92fa20b 100644 --- a/src/libopensrf/osrf_cache.c +++ b/src/libopensrf/osrf_cache.c @@ -53,7 +53,7 @@ jsonObject* osrfCacheGetObject( const char* key, ... ) { 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 @@ char* osrfCacheGetString( const char* key, ... ) { 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 @@ int osrfCacheSetExpire( time_t seconds, const char* key, ... ) { 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; } -- 2.43.2