couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [5/8] git commit: Fix resource destructors
Date Fri, 01 Aug 2014 09:06:18 GMT
Fix resource destructors

Apparently the resource name is quite important. The old code was
attempting to free all hashes with the iterator destructor which also
had a bug that masked the underlying issue. This fixes the wrong
destructor issue as well as the iterator destructor bug.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-khash/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-khash/commit/f87d8bc7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-khash/tree/f87d8bc7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-khash/diff/f87d8bc7

Branch: refs/heads/windsor-merge
Commit: f87d8bc73221f8e6c94761e9486b4fcbfd395e25
Parents: 36cccf3
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Fri Aug 16 11:14:44 2013 -0500
Committer: Robert Newson <rnewson@apache.org>
Committed: Wed Jul 30 17:16:33 2014 +0100

----------------------------------------------------------------------
 c_src/khash.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-khash/blob/f87d8bc7/c_src/khash.c
----------------------------------------------------------------------
diff --git a/c_src/khash.c b/c_src/khash.c
index 038c81c..d206f5e 100644
--- a/c_src/khash.c
+++ b/c_src/khash.c
@@ -493,7 +493,7 @@ static void
 khash_iter_free(ErlNifEnv* env, void* obj)
 {
     khash_iter_t* iter = (khash_iter_t*) obj;
-    enif_release_resource(iter);
+    enif_release_resource(iter->khash);
 }
 
 
@@ -538,7 +538,6 @@ khash_iter_next(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
 static int
 load(ErlNifEnv* env, void** priv, ERL_NIF_TERM info)
 {
-    const char* mod = "khash";
     int flags = ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER;
     ErlNifResourceType* res;
 
@@ -547,13 +546,15 @@ load(ErlNifEnv* env, void** priv, ERL_NIF_TERM info)
         return 1;
     }
 
-    res = enif_open_resource_type(env, mod, "", khash_free, flags, NULL);
+    res = enif_open_resource_type(
+            env, NULL, "khash", khash_free, flags, NULL);
     if(res == NULL) {
         return 1;
     }
     new_priv->res_hash = res;
 
-    res = enif_open_resource_type(env, mod, "", khash_iter_free, flags, NULL);
+    res = enif_open_resource_type(
+            env, NULL, "khash_iter", khash_iter_free, flags, NULL);
     if(res == NULL) {
         return 1;
     }


Mime
View raw message