Archive

Monthly Archives: January 2014

To speedup my web application backed by PostgreSQL, query results is cached in Memcached. I have been using pgmemcache extension, so I can communicate with the distributed memory object caching system from within my stored procedure.

The postgresql extension code is based on libmemcached. And I have noticed that start from version 1.0.16, libmemcached has modified codes within memcached_stat_get_value function (defined in stats.cc). The resulted string is no longer allocated by customized allocator, but using malloc instead. If pgmemcache version>= 2.0.1 (2.1.2 in my case) is built against the libmemcached version, postgresql will crash once you invoke:
abduldb=# select memcache_stats();

The fix is simply modify memory deallocation from pfree() to free() for string after memcached_stat_get_value in Datum memcache_stats(PG_FUNCTION_ARGS) or server_stat_function(…) (defined in pgmemcache.c):

char *value = memcached_stat_get_value(ptr, &stat, *stat_ptr, &rc);
appendStringInfo(context, "%s: %s\n", *stat_ptr, value);
//pfree(value);
free(value);
Advertisements