From 8d7bbebe0c7594f673c53b1d8066a8d0e9fc5350 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 19 Mar 2019 11:52:15 +0100 Subject: [socket] Another try at fixing the NULL env During socket stop the close environment somehow has been NULLed. Check this before using when sending the close message. --- erts/emulator/nifs/common/socket_nif.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'erts/emulator/nifs/common/socket_nif.c') diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c index 654e5b6a9d..f131b45685 100644 --- a/erts/emulator/nifs/common/socket_nif.c +++ b/erts/emulator/nifs/common/socket_nif.c @@ -16898,12 +16898,15 @@ char* esock_send_close_msg(ErlNifEnv* env, SocketDescriptor* descP, ERL_NIF_TERM sockRef) { - char* res = esock_send_socket_msg(env, - enif_make_copy(descP->closeEnv, sockRef), - esock_atom_close, - descP->closeRef, - &descP->closerPid, - descP->closeEnv); + ERL_NIF_TERM sr = ((descP->closeEnv != NULL) ? + enif_make_copy(descP->closeEnv, sockRef) : + sockRef); + char* res = esock_send_socket_msg(env, + sr, + esock_atom_close, + descP->closeRef, + &descP->closerPid, + descP->closeEnv); descP->closeEnv = NULL; @@ -17765,6 +17768,7 @@ void socket_stop(ErlNifEnv* env, void* obj, int fd, int is_direct_call) if (descP->sock != INVALID_SOCKET) { if (descP->closeLocal) { + if (!is_direct_call) { /* +++ send close message to the waiting process +++ */ @@ -17779,7 +17783,11 @@ void socket_stop(ErlNifEnv* env, void* obj, int fd, int is_direct_call) * since the message send takes care of it if scheduled. */ - if (descP->closeEnv != NULL) enif_free_env(descP->closeEnv); + if (descP->closeEnv != NULL) { + enif_clear_env(descP->closeEnv); + enif_free_env(descP->closeEnv); + descP->closeEnv = NULL; + } } } -- cgit v1.2.3