Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: segfault due to use unsafe env #56

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions c_src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,22 @@ erlfdb_future_cb(FDBFuture* fdb_future, void* data)
// submitted to the network thread or not so that
// we pass the correct environment to enif_send
if(enif_thread_type() == ERL_NIF_THR_UNDEFINED) {
enif_mutex_lock(future->lock);
caller = NULL;
} else {
caller = future->pid_env;
}

enif_mutex_lock(future->lock);


if(!future->cancelled) {
msg = T2(future->msg_env, future->msg_ref, ATOM_ready);
enif_send(caller, &(future->pid), future->msg_env, msg);
}

enif_mutex_unlock(future->lock);
if (!caller) {
enif_mutex_unlock(future->lock);
}

// We're now done with this future which means we need
// to release our handle to it. See erlfdb_create_future
Expand Down Expand Up @@ -591,7 +594,7 @@ erlfdb_future_cancel(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
future = (ErlFDBFuture*) res;

enif_mutex_lock(future->lock);

future->pid_env = env;
future->cancelled = true;
fdb_future_cancel(future->future);

Expand Down