I implemented one class to handle all zookeeper stuff. In connect(), I used m_zh = zookeeper_init( m_zkUrl.c_str(), NULL, 10000, 0, NULL, 0 ); to get a zookeeper handler. In the class destructor, I used zookeeper_close( m_zh ); to free this zookeeper handler. Why there still some memory leak? The output of valgrind is following.
...
==5003== 300 (60 direct, 240 indirect) bytes in 1 blocks are definitely lost in loss record 11 of 13
==5003== at 0x4C2CFA7: malloc (vg_replace_malloc.c:296)
==5003== by 0x596A594: nss_parse_service_list (nsswitch.c:678)
==5003== by 0x596B055: __nss_database_lookup (nsswitch.c:175)
==5003== by 0x6028623: ???
==5003== by 0x5923BFC: getpwuid_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==5003== by 0x5946E6E: __getlogin_r_loginuid (getlogin_r.c:68)
==5003== by 0x5946BC4: getlogin (getlogin.c:35)
==5003== by 0x4044D4: log_env (zookeeper.c:733)
==5003== by 0x406026: zookeeper_init (zookeeper.c:770)
==5003== by 0x402FFC: ZKConnection::connect() (zkconnection.cpp:37)
==5003== by 0x402962: main (test_zk.cpp:44)
...
==4624== LEAK SUMMARY:
==4624== definitely lost: 60 bytes in 1 blocks
==4624== indirectly lost: 240 bytes in 10 blocks
==4624== possibly lost: 0 bytes in 0 blocks
==4624== still reachable: 5,120 bytes in 2 blocks
==4624== suppressed: 0 bytes in 0 blocks