Browse files

Fix very elusive GC-triggered VM crash caused by pulse_send()

This fix appears to fix a very vexing, elusive VM crash that
is triggered well after the data-corrupting fact by a major
GC event.

After experimenting many different ways with trying to find
the problem, using valgrind + a specific test case that
managed to always provoke the problem.  It was quite difficult
to find a deterministic counter-example -- almost all were
ones that would succeed most of the time and only fail once
every 20 or 50 or 200 attempts.

Fix: use the same env for all parts of the term that we send
     to the PULSE process.
  • Loading branch information...
1 parent 5c85c0c commit ac9bec8fe3046308c5c63811c887f37a3e4c8e88 @slfritchie slfritchie committed Nov 13, 2012
Showing with 5 additions and 5 deletions.
  1. +5 −5 c_src/pulse_c_send.c
@@ -36,12 +36,12 @@ int pulse_send(ErlNifEnv* env, ErlNifPid* dest_pid,
ErlNifEnv* msg_env, ERL_NIF_TERM msg,
char* file, int line){
ERL_NIF_TERM t_self =
- enif_make_pid(env, enif_self(env, (ErlNifPid *)malloc(sizeof(ErlNifPid))));
+ enif_make_pid(msg_env, enif_self(msg_env, (ErlNifPid *)malloc(sizeof(ErlNifPid))));
ERL_NIF_TERM t_src_loc =
- enif_make_tuple2(env, enif_make_string(env, file, ERL_NIF_LATIN1),
- enif_make_int(env, line));
- ERL_NIF_TERM t_args = enif_make_list(env, 2, enif_make_pid(env, dest_pid), msg);
- ERL_NIF_TERM pulse_msg = enif_make_tuple4(env,
+ enif_make_tuple2(msg_env, enif_make_string(msg_env, file, ERL_NIF_LATIN1),
+ enif_make_int(msg_env, line));
+ ERL_NIF_TERM t_args = enif_make_list(msg_env, 2, enif_make_pid(msg_env, dest_pid), msg);
+ ERL_NIF_TERM pulse_msg = enif_make_tuple4(msg_env,

0 comments on commit ac9bec8

Please sign in to comment.