You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2019/02/22 17:28:14 UTC
[couchdb-khash] 07/25: Fix resource destructors
This is an automated email from the ASF dual-hosted git repository.
jaydoane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-khash.git
commit f87d8bc73221f8e6c94761e9486b4fcbfd395e25
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Fri Aug 16 11:14:44 2013 -0500
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.
---
c_src/khash.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
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;
}