浏览代码

ZOOKEEPER-1163. Memory leak in zk_hashtable.c:do_insert_watcher_object() (Anupam Chanda via michim)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1353683 13f79535-47bb-0310-9956-ffa450edef68
Michi Mutsuzaki 13 年之前
父节点
当前提交
e613fbd567
共有 2 个文件被更改,包括 9 次插入2 次删除
  1. 3 0
      CHANGES.txt
  2. 6 2
      src/c/src/zk_hashtable.c

+ 3 - 0
CHANGES.txt

@@ -185,6 +185,9 @@ BUGFIXES:
 
   ZOOKEEPER-1431. zkpython async calls leak memory (Kapil Thangavelu and Andre Cruz via henryr)
 
+  ZOOKEEPER-1163. Memory leak in zk_hashtable.c:do_insert_watcher_object()
+  (Anupam Chanda via michim)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

+ 6 - 2
src/c/src/zk_hashtable.c

@@ -189,8 +189,12 @@ static int do_insert_watcher_object(zk_hashtable *ht, const char *path, watcher_
         res=hashtable_insert(ht->ht,strdup(path),create_watcher_object_list(wo));
         assert(res);
     }else{
-        /* path already exists; check if the watcher already exists */
-        res = add_to_list(&wl, wo, 1);
+        /*
+         * Path already exists; check if the watcher already exists.
+         * Don't clone the watcher since it's allocated on the heap --- avoids
+         * a memory leak and saves a clone operation (calloc + copy).
+         */
+        res = add_to_list(&wl, wo, 0);
     }
     return res;    
 }