{"action":"created","issue":{"url":"https://api.github.com/repos/redis/hiredis/issues/355","labels_url":"https://api.github.com/repos/redis/hiredis/issues/355/labels{/name}","comments_url":"https://api.github.com/repos/redis/hiredis/issues/355/comments","events_url":"https://api.github.com/repos/redis/hiredis/issues/355/events","html_url":"https://github.com/redis/hiredis/issues/355","id":103219981,"number":355,"title":"Memory leak when redisAsyncConnect failed?","user":{"login":"owt5008137","id":1209475,"avatar_url":"https://avatars.githubusercontent.com/u/1209475?v=3","gravatar_id":"","url":"https://api.github.com/users/owt5008137","html_url":"https://github.com/owt5008137","followers_url":"https://api.github.com/users/owt5008137/followers","following_url":"https://api.github.com/users/owt5008137/following{/other_user}","gists_url":"https://api.github.com/users/owt5008137/gists{/gist_id}","starred_url":"https://api.github.com/users/owt5008137/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owt5008137/subscriptions","organizations_url":"https://api.github.com/users/owt5008137/orgs","repos_url":"https://api.github.com/users/owt5008137/repos","events_url":"https://api.github.com/users/owt5008137/events{/privacy}","received_events_url":"https://api.github.com/users/owt5008137/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-26T09:26:01Z","updated_at":"2015-08-26T11:56:07Z","closed_at":null,"body":"I‘m trying to write a [library for redis-cluster](https://github.com/owt5008137/hiredis-happ) using hiredis.\r\nAnd It seems to have memory leak when I use valgrind to run unit test。\r\n\r\nMy environment:\r\nUbuntu 12.04 Server LTS.\r\ngcc 4.6.3.\r\nuse libuv for event dispatch.\r\n\r\n```bash\r\n# cmd\r\nvalgrind --tool=memcheck -v --leak-check=full test/hiredis-happ-test 2>err.log\r\n```\r\nCode actions:\r\n1. using **redisAsyncConnect** to connect to a invalid address and port.(127.0.0.1:6370)\r\n2. send CLUSTER SLOTS command to the async context\r\n3. using **redisAsyncDisconnect** to close context\r\n\r\ntail content of err.log\r\n```\r\n101 ==10282==\r\n102 ==10282== HEAP SUMMARY:\r\n103 ==10282==     in use at exit: 1,100 bytes in 8 blocks\r\n104 ==10282==   total heap usage: 163 allocs, 155 frees, 9,997 bytes allocated\r\n105 ==10282==\r\n106 ==10282== Searching for pointers to 8 not-freed blocks\r\n107 ==10282== Checked 195,704 bytes\r\n108 ==10282==\r\n109 ==10282== 1,100 (344 direct, 756 indirect) bytes in 1 blocks are definitely lost in loss record 8 of 8\r\n110 ==10282==    at 0x4C2B7B2: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n111 ==10282==    by 0x4E39ABA: redisAsyncInitialize (async.c:108)\r\n112 ==10282==    by 0x4E3A4EB: redisAsyncConnect (async.c:161)\r\n113 ==10282==    by 0x430602: hiredis::happ::cluster::make_connection(hiredis::happ::connection::key_t const&) (happ_cluster.cpp:371)\r\n114 ==10282==    by 0x4301C7: hiredis::happ::cluster::reload_slots() (happ_cluster.cpp:296)\r\n115 ==10282==    by 0x42F673: hiredis::happ::cluster::start() (happ_cluster.cpp:61)\r\n116 ==10282==    by 0x421DED: test_func_test_happ_cluster_case_connection_callback() (hiredis_happ_cluster_test.cpp:51)\r\n117 ==10282==    by 0x42DB8E: test_case_base::run() (test_case_base.cpp:36)\r\n118 ==10282==    by 0x42669E: test_manager::run() (test_manager.cpp:82)\r\n119 ==10282==    by 0x4271A5: run_tests() (test_manager.cpp:157)\r\n120 ==10282==    by 0x426207: main (main.cpp:53)\r\n121 ==10282==\r\n122 ==10282== LEAK SUMMARY:\r\n123 ==10282==    definitely lost: 344 bytes in 1 blocks\r\n124 ==10282==    indirectly lost: 756 bytes in 7 blocks\r\n125 ==10282==      possibly lost: 0 bytes in 0 blocks\r\n126 ==10282==    still reachable: 0 bytes in 0 blocks\r\n127 ==10282==         suppressed: 0 bytes in 0 blocks\r\n128 ==10282==\r\n129 ==10282== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)\r\n130 --10282--\r\n131 --10282-- used_suppression:      2 dl-hack3-cond-1\r\n132 ==10282==\r\n133 ==10282== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)\r\n```\r\n\r\nPS: reply callback is not called either."},"comment":{"url":"https://api.github.com/repos/redis/hiredis/issues/comments/134963328","html_url":"https://github.com/redis/hiredis/issues/355#issuecomment-134963328","issue_url":"https://api.github.com/repos/redis/hiredis/issues/355","id":134963328,"user":{"login":"badboy","id":2129,"avatar_url":"https://avatars.githubusercontent.com/u/2129?v=3","gravatar_id":"","url":"https://api.github.com/users/badboy","html_url":"https://github.com/badboy","followers_url":"https://api.github.com/users/badboy/followers","following_url":"https://api.github.com/users/badboy/following{/other_user}","gists_url":"https://api.github.com/users/badboy/gists{/gist_id}","starred_url":"https://api.github.com/users/badboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/badboy/subscriptions","organizations_url":"https://api.github.com/users/badboy/orgs","repos_url":"https://api.github.com/users/badboy/repos","events_url":"https://api.github.com/users/badboy/events{/privacy}","received_events_url":"https://api.github.com/users/badboy/received_events","type":"User","site_admin":false},"created_at":"2015-08-26T11:56:07Z","updated_at":"2015-08-26T11:56:07Z","body":"I currently can't reproduce it with the minimal example included in this repository. I also re-read the relevant code parts, but don't really see where the memory leak should happen (that of course doesn't mean it really can't).\r\n\r\nSo any more insight or a proper (small) test to reproduce it can help."}}