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.

Scott McKellar
http://home.swbell.net/mck9/ct/

Developer's Certificate of Origin 1.1 By making a contribution to
this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license indicated
in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source license
and I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under the
same open source license (unless I am permitted to submit under a
different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person
who certified (a), (b) or (c) and I have not modified it; and

(d) In the case of each of (a), (b), or (c), I understand and agree
that this project and the contribution are public and that a record
of the contribution (including all personal information I submit
with it, including my sign-off) is maintained indefinitely and may
be redistributed consistent with this project or the open source
license indicated in the file.
*** ./trunk/src/libopensrf/osrf_cache.c	2008-01-31 17:42:45.000000000 -0600
--- ./trunk-mod/src/libopensrf/osrf_cache.c	2008-02-02 11:35:22.000000000 -0600
***************
*** 52,58 ****
  	jsonObject* obj = NULL;
  	if( key ) {
  		VA_LIST_TO_STRING(key);
! 		char* data = (char*) mc_aget( _osrfCache, VA_BUF, strlen(VA_BUF) );
  		if( data ) {
  			osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetObject(): Returning object: %s", data);
  			obj = jsonParseString( data );
--- 52,58 ----
  	jsonObject* obj = NULL;
  	if( key ) {
  		VA_LIST_TO_STRING(key);
! 		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 );
***************
*** 67,73 ****
  	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);
  		if(!data) osrfLogWarning(OSRF_LOG_MARK, "No cache data exists with key %s", VA_BUF);
  		return data;
  	}
--- 67,73 ----
  	if( key ) {
  		VA_LIST_TO_STRING(key);
  		char* data = (char*) mc_aget(_osrfCache, VA_BUF, strlen(VA_BUF) );
! 		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;
  	}
***************
*** 89,95 ****
  		VA_LIST_TO_STRING(key);
  		jsonObject* o = osrfCacheGetObject( VA_BUF );
  		//osrfCacheRemove(VA_BUF);
! 		return osrfCachePutObject( VA_BUF, o, seconds );
  	}
  	return -1;
  }
--- 89,97 ----
  		VA_LIST_TO_STRING(key);
  		jsonObject* o = osrfCacheGetObject( VA_BUF );
  		//osrfCacheRemove(VA_BUF);
! 		int rc = osrfCachePutObject( VA_BUF, o, seconds );
! 		jsonObjectFree(o);
! 		return rc;
  	}
  	return -1;
  }

Reply via email to