From 480a7bca3397430d499cd42fb35fabd168a73138 Mon Sep 17 00:00:00 2001 From: Ilya Averyanov Date: Fri, 12 Apr 2024 09:49:56 +0300 Subject: [PATCH] fix: free msg_env unconditionally --- c_src/main.c | 10 +--------- c_src/resources.c | 4 ---- c_src/resources.h | 1 - 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/c_src/main.c b/c_src/main.c index 3918f7e..3a68009 100644 --- a/c_src/main.c +++ b/c_src/main.c @@ -86,23 +86,16 @@ erlfdb_future_cb(FDBFuture* fdb_future, void* data) cancelled = future->cancelled; enif_mutex_unlock(future->cancel_lock); - enif_mutex_lock(future->msg_lock); - if(future->msg_env != NULL) { - if(!cancelled) { proc_env = (ErlNifEnv*) erl_drv_tsd_get(future->future_proc_env_key); msg = T2(future->msg_env, future->msg_ref, ATOM_ready); enif_send(proc_env, &(future->pid), future->msg_env, msg); - } else { - enif_free_env(future->msg_env); } - + enif_free_env(future->msg_env); future->msg_env = NULL; } - enif_mutex_unlock(future->msg_lock); - // We're now done with this future which means we need // to release our handle to it. See erlfdb_create_future // for more on why this happens here. @@ -132,7 +125,6 @@ erlfdb_create_future(ErlNifEnv* env, FDBFuture* future, ErlFDBFutureGetter gette enif_self(env, &(f->pid)); f->msg_env = enif_alloc_env(); f->msg_ref = enif_make_copy(f->msg_env, ref); - f->msg_lock = enif_mutex_create("fdb:future_msg_lock"); f->cancelled = false; f->cancel_lock = enif_mutex_create("fdb:future_cancel_lock"); diff --git a/c_src/resources.c b/c_src/resources.c index bc0bebd..f418e2b 100644 --- a/c_src/resources.c +++ b/c_src/resources.c @@ -90,10 +90,6 @@ erlfdb_future_dtor(ErlNifEnv* env, void* obj) if(f->cancel_lock != NULL) { enif_mutex_destroy(f->cancel_lock); } - - if(f->msg_lock != NULL) { - enif_mutex_destroy(f->msg_lock); - } } diff --git a/c_src/resources.h b/c_src/resources.h index 129dc33..237616a 100644 --- a/c_src/resources.h +++ b/c_src/resources.h @@ -36,7 +36,6 @@ struct _ErlFDBFuture ErlNifPid pid; ErlNifEnv* msg_env; ERL_NIF_TERM msg_ref; - ErlNifMutex* msg_lock; ErlDrvTSDKey future_proc_env_key; bool cancelled; ErlNifMutex* cancel_lock;