memory leak in memcached_servers_parse

Bug #728286 reported by Ken
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
libmemcached
Fix Released
Medium
Brian Aker

Bug Description

#include <libmemcached/memcached.h>
 int main() {
  memcached_server_st *servers = memcached_servers_parse("1.2.3.4:99");
  memcached_server_free(servers);
  return 0;
}

gcc leak_test.c -lmemcached -lm -o leak_test

use valgrind we got:
==10925== 17,516 bytes in 1 blocks are definitely lost in loss record 1 of 1
==10925== at 0x4025BD3: malloc (vg_replace_malloc.c:236)
==10925== by 0x4025C5D: realloc (vg_replace_malloc.c:525)
==10925== by 0x80494FD: memcached_server_list_append_with_weight (server_list.c:37)
==10925== by 0x8048EFF: memcached_servers_parse (parse.c:67)
==10925== by 0x8048D88: main (in ...../leak_test)

maybe reason:
  memcached_server_free depend on options.is_allocated, but, when we call
  memcached_server_create_with, options.is_allocated is set to 0

patch attached, wish helped.

Ken

Tags: leak memory
Revision history for this message
Ken (boostguy) wrote :
Brian Aker (brianaker)
Changed in libmemcached:
assignee: nobody → Brian Aker (brianaker)
importance: Undecided → Medium
Revision history for this message
Brian Aker (brianaker) wrote :

Thanks, when I try your patch out I get the following:

#0 memcached_server_free (self=<value optimized out>) at libmemcached/server.c:118
#1 0x0000000000409a46 in regression_bug_728286 (unused=<value optimized out>) at tests/mem_functions.c:6130

When free is called if root is not set in the structure we get a crash. I've added an if() to that to solve the issue.

I should have this in trunk sometime in the next 24hours.

Thanks again.

Brian Aker (brianaker)
Changed in libmemcached:
status: New → Fix Committed
Brian Aker (brianaker)
Changed in libmemcached:
status: Fix Committed → Fix Released
Revision history for this message
Brian Aker (brianaker) wrote :

Looking back at this, I see a mistake in the example.

memcached_servers_parse() creates a list, not a memcached_server_st. The memory from it needs to be cleaned up with memcached_server_list_free().

I believe I can make the above work without changing the API.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.