aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2019-02-08 17:07:17 +0100
committerMicael Karlberg <[email protected]>2019-02-22 19:45:52 +0100
commit80f6b095e54dec9ed6f0b0b77eabdb088c797cb9 (patch)
treee0d90b4e039f81ae5b26a14356fad5ac72a09bed /erts
parentb86fde22bc723505292a1094e918e2b40c3989f2 (diff)
downloadotp-80f6b095e54dec9ed6f0b0b77eabdb088c797cb9.tar.gz
otp-80f6b095e54dec9ed6f0b0b77eabdb088c797cb9.tar.bz2
otp-80f6b095e54dec9ed6f0b0b77eabdb088c797cb9.zip
[socket-nif] Fix bug in message sending
Asserts failed in debug vm as msg term was built from mixed ErlNifEnv's.
Diffstat (limited to 'erts')
-rw-r--r--erts/emulator/nifs/common/socket_nif.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c
index 61d17bddb1..195b2199a1 100644
--- a/erts/emulator/nifs/common/socket_nif.c
+++ b/erts/emulator/nifs/common/socket_nif.c
@@ -2348,10 +2348,12 @@ static char* esock_send_socket_msg(ErlNifEnv* env,
ERL_NIF_TERM sockRef,
ERL_NIF_TERM tag,
ERL_NIF_TERM info,
- ErlNifPid* pid);
+ ErlNifPid* pid,
+ ErlNifEnv* msg_env);
static char* esock_send_msg(ErlNifEnv* env,
ERL_NIF_TERM msg,
- ErlNifPid* pid);
+ ErlNifPid* pid,
+ ErlNifEnv* msg_env);
static BOOLEAN_T extract_debug(ErlNifEnv* env,
ERL_NIF_TERM map);
@@ -16652,7 +16654,7 @@ char* esock_send_close_msg(ErlNifEnv* env,
{
return esock_send_socket_msg(env,
esock_atom_undefined,
- esock_atom_close, closeRef, pid);
+ esock_atom_close, closeRef, pid, NULL);
}
@@ -16671,7 +16673,9 @@ char* esock_send_abort_msg(ErlNifEnv* env,
ERL_NIF_TERM reason,
ErlNifPid* pid)
{
- ERL_NIF_TERM info = MKT2(env, recvRef, reason);
+ ErlNifEnv* msg_env = enif_alloc_env();
+ ERL_NIF_TERM info = MKT2(msg_env, enif_make_copy(msg_env, recvRef),
+ enif_make_copy(msg_env, reason));
/*
esock_dbg_printf("SEND MSG",
@@ -16682,7 +16686,8 @@ char* esock_send_abort_msg(ErlNifEnv* env,
"\r\n", *pid, sockRef, recvRef, reason);
*/
- return esock_send_socket_msg(env, sockRef, esock_atom_abort, info, pid);
+ return esock_send_socket_msg(env, sockRef, esock_atom_abort, info, pid,
+ msg_env);
}
@@ -16700,11 +16705,19 @@ char* esock_send_socket_msg(ErlNifEnv* env,
ERL_NIF_TERM sockRef,
ERL_NIF_TERM tag,
ERL_NIF_TERM info,
- ErlNifPid* pid)
-{
- ERL_NIF_TERM msg = MKT4(env, esock_atom_socket_tag, sockRef, tag, info);
+ ErlNifPid* pid,
+ ErlNifEnv* msg_env)
+{
+ ERL_NIF_TERM msg;
+ if (!msg_env) {
+ msg_env = enif_alloc_env();
+ sockRef = enif_make_copy(msg_env, sockRef);
+ tag = enif_make_copy(msg_env, tag);
+ info = enif_make_copy(msg_env, info);
+ }
+ msg = MKT4(msg_env, esock_atom_socket_tag, sockRef, tag, info);
- return esock_send_msg(env, msg, pid);
+ return esock_send_msg(env, msg, pid, msg_env);
}
@@ -16713,9 +16726,14 @@ char* esock_send_socket_msg(ErlNifEnv* env,
static
char* esock_send_msg(ErlNifEnv* env,
ERL_NIF_TERM msg,
- ErlNifPid* pid)
+ ErlNifPid* pid,
+ ErlNifEnv* msg_env)
{
- if (!enif_send(env, pid, NULL, msg))
+ int res = enif_send(env, pid, msg_env, msg);
+ if (msg_env)
+ enif_free_env(msg_env);
+
+ if (!res)
return str_exsend;
else
return NULL;