zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhangyafeikimi <zhangyafeik...@gmail.com>
Subject Report some memory leaks in zookeeper-3.3.3 c client
Date Fri, 29 Jul 2011 04:18:12 GMT
hi, all

I am working with zookeeper-3.3.3 c client, some heavy memory leaks are
found.
Help!
Thanks!

the prgram is like this:

#include <stdio.h>
#include &lt;sys/time.h&gt;
#include <pthread.h>
#include <zookeeper.h>


void watcher(zhandle_t * zh,
             int event,
             int state,
             const char * path,
             void * watcher_context)
{
}


void free_string_vector(struct String_vector * sv)
{
  if (sv)
  {
    int i;
    for (i=0; i<sv->count; i++)
    {
      free(sv->data[i]);
      sv->data[i] = 0;
    }
    free(sv->data);

    sv->count = 0;
    sv->data = 0;
  }
}


void * thread_routine(void * p)
{
  zhandle_t * zh;
  struct String_vector service_names;
  struct timeval begin, end;
  int rc, i, ms;

  zh = zookeeper_init("job:2181", watcher, 30000, 0, 0, 0);

  gettimeofday(&begin, 0);
  for (i=0; i<100; i++)
  {
    rc = zoo_get_children(zh, "/ns", 1, &service_names);
    if (rc != ZOK)
      break;
    free_string_vector(&service_names);
  }
  gettimeofday(&end, 0);
  ms = (end.tv_sec - begin.tv_sec)*1000.0 +
    (end.tv_usec - begin.tv_usec)/1000.0 + 0.5;
  printf("%d times zoo_get_children cost %d ms\n", i, ms);

  zookeeper_close(zh);
  return 0;
}


int main()
{
#define THREAD_NUMBER 10
  pthread_t tid[THREAD_NUMBER];
  int i;

  zoo_set_debug_level(ZOO_LOG_LEVEL_ERROR);

  for (i=0; i<THREAD_NUMBER; i++)
  {
    pthread_create(&tid[i], 0, thread_routine, 0);
  }


  for (i=0; i<THREAD_NUMBER; i++)
  {
    pthread_join(tid[i], 0);
  }

  return 0;
}




the valgrind output is like this:

==13552== Memcheck, a memory error detector.
==13552== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==13552== Using LibVEX rev 1854, a library for dynamic binary translation.
==13552== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==13552== Using valgrind-3.3.1-Debian, a dynamic binary instrumentation
framework.
==13552== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==13552== For more details, rerun with: -v
==13552== 
100 times zoo_get_children cost 3835 ms
100 times zoo_get_children cost 4534 ms
100 times zoo_get_children cost 6485 ms
100 times zoo_get_children cost 6389 ms
100 times zoo_get_children cost 7831 ms
100 times zoo_get_children cost 9578 ms
100 times zoo_get_children cost 11551 ms
100 times zoo_get_children cost 11636 ms
100 times zoo_get_children cost 13202 ms
100 times zoo_get_children cost 15399 ms
==13552== 
==13552== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 42 from 2)
==13552== malloc/free: in use at exit: 94,652 bytes in 1,104 blocks.
==13552== malloc/free: 25,494 allocs, 24,390 frees, 1,356,358 bytes
allocated.
==13552== For counts of detected errors, rerun with: -v
==13552== searching for pointers to 1,104 not-freed blocks.
==13552== checked 108,544 bytes.
==13552== 
==13552== 3,600 bytes in 90 blocks are definitely lost in loss record 2 of 5
==13552==    at 0x4C2260E: malloc (vg_replace_malloc.c:207)
==13552==    by 0xAC3B4AD: ???
==13552==    by 0xAC3BBFB: ???
==13552==    by 0xAC3BD18: ???
==13552==    by 0xAC3226C: ???
==13552==    by 0xAC350A0: ???
==13552==    by 0xAC3583E: ???
==13552==    by 0xAC35DF8: ???
==13552==    by 0x5362181: getpwuid_r (in /lib/libc-2.7.so)
==13552==    by 0x40873C: log_env (zookeeper.c:686)
==13552==    by 0x40919A: zookeeper_init (zookeeper.c:716)
==13552==    by 0x4022BE: thread_routine (test.c:89)
==13552== 
==13552== 
==13552== 67,292 (1,104 direct, 66,188 indirect) bytes in 2 blocks are
definitely lost in loss record 3 of 5
==13552==    at 0x4C203E4: calloc (vg_replace_malloc.c:397)
==13552==    by 0xB09EFA4: ???
==13552==    by 0xAE5EC9E: ???
==13552==    by 0xAE5F1E9: ???
==13552==    by 0xAC3217B: ???
==13552==    by 0xAC350A0: ???
==13552==    by 0xAC3583E: ???
==13552==    by 0xAC35DF8: ???
==13552==    by 0x5362181: getpwuid_r (in /lib/libc-2.7.so)
==13552==    by 0x40873C: log_env (zookeeper.c:686)
==13552==    by 0x40919A: zookeeper_init (zookeeper.c:716)
==13552==    by 0x4022BE: thread_routine (test.c:89)
==13552== 
==13552== 
==13552== 23,760 bytes in 990 blocks are definitely lost in loss record 4 of
5
==13552==    at 0x4C203E4: calloc (vg_replace_malloc.c:397)
==13552==    by 0x40A567: activateWatcher (zk_hashtable.c:85)
==13552==    by 0x406F13: zookeeper_process (zookeeper.c:1975)
==13552==    by 0x409E6E: do_io (mt_adaptor.c:310)
==13552==    by 0x4E2CFC6: start_thread (in /lib/libpthread-2.7.so)
==13552==    by 0x539464C: clone (in /lib/libc-2.7.so)
==13552== 
==13552== LEAK SUMMARY:
==13552==    definitely lost: 28,464 bytes in 1,082 blocks.
==13552==    indirectly lost: 66,188 bytes in 22 blocks.
==13552==      possibly lost: 0 bytes in 0 blocks.
==13552==    still reachable: 0 bytes in 0 blocks.
==13552==         suppressed: 0 bytes in 0 blocks.


--
View this message in context: http://zookeeper-user.578899.n2.nabble.com/Report-some-memory-leaks-in-zookeeper-3-3-3-c-client-tp6632319p6632319.html
Sent from the zookeeper-user mailing list archive at Nabble.com.

Mime
View raw message