aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/nifs/common/socket_nif.c
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2019-03-19 11:52:15 +0100
committerMicael Karlberg <[email protected]>2019-03-19 11:52:15 +0100
commit8d7bbebe0c7594f673c53b1d8066a8d0e9fc5350 (patch)
treed85c524b71d45f8a8c66edcc24ebcf56cccb29d2 /erts/emulator/nifs/common/socket_nif.c
parent47437fc6d9dd6a48a949dea3a33e66f40fa6431d (diff)
downloadotp-8d7bbebe0c7594f673c53b1d8066a8d0e9fc5350.tar.gz
otp-8d7bbebe0c7594f673c53b1d8066a8d0e9fc5350.tar.bz2
otp-8d7bbebe0c7594f673c53b1d8066a8d0e9fc5350.zip
[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.
Diffstat (limited to 'erts/emulator/nifs/common/socket_nif.c')
-rw-r--r--erts/emulator/nifs/common/socket_nif.c22
1 files changed, 15 insertions, 7 deletions
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;
+ }
}
}