pgmemcache: crashes on memcache_stats()

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 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);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: