You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by mi...@apache.org on 2012/06/25 19:50:43 UTC

svn commit: r1353683 - in /zookeeper/trunk: CHANGES.txt src/c/src/zk_hashtable.c

Author: michim
Date: Mon Jun 25 17:50:42 2012
New Revision: 1353683

URL: http://svn.apache.org/viewvc?rev=1353683&view=rev
Log:
ZOOKEEPER-1163. Memory leak in zk_hashtable.c:do_insert_watcher_object() (Anupam Chanda via michim)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/c/src/zk_hashtable.c

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1353683&r1=1353682&r2=1353683&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Mon Jun 25 17:50:42 2012
@@ -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,

Modified: zookeeper/trunk/src/c/src/zk_hashtable.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/zk_hashtable.c?rev=1353683&r1=1353682&r2=1353683&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/zk_hashtable.c (original)
+++ zookeeper/trunk/src/c/src/zk_hashtable.c Mon Jun 25 17:50:42 2012
@@ -189,8 +189,12 @@ static int do_insert_watcher_object(zk_h
         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;    
 }