aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/nifs
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2019-02-06 16:31:41 +0100
committerMicael Karlberg <[email protected]>2019-02-22 19:45:52 +0100
commitfa6e81982e8f41f58e1c20995b9e5644622bf40c (patch)
tree36f663def4e55dd7032673ed8a3ab0f66f79cc8a /erts/emulator/nifs
parentb278a8bba833a681d692fc95f3c77c57f2d0ac69 (diff)
downloadotp-fa6e81982e8f41f58e1c20995b9e5644622bf40c.tar.gz
otp-fa6e81982e8f41f58e1c20995b9e5644622bf40c.tar.bz2
otp-fa6e81982e8f41f58e1c20995b9e5644622bf40c.zip
[socket-nif] Fix memorys leaks in recv error cases
and collapsed some duplicate code
Diffstat (limited to 'erts/emulator/nifs')
-rw-r--r--erts/emulator/nifs/common/socket_nif.c63
1 files changed, 20 insertions, 43 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c
index f97e5b6867..61d17bddb1 100644
--- a/erts/emulator/nifs/common/socket_nif.c
+++ b/erts/emulator/nifs/common/socket_nif.c
@@ -13580,7 +13580,6 @@ ERL_NIF_TERM send_check_result(ErlNifEnv* env,
return res;
} else {
-
/* Ok, try again later */
SSDBG( descP, ("SOCKET", "send_check_result -> try again\r\n") );
@@ -13907,47 +13906,29 @@ ERL_NIF_TERM recv_check_result(ErlNifEnv* env,
return esock_make_ok3(env, atom_true, data);
- } else {
+ }
+ }
- /* Yes, we *do* need to continue reading */
+ /* Yes, we *do* need to continue reading */
- if ((xres = recv_init_current_reader(env,
- descP, recvRef)) != NULL) {
- descP->rNumCnt = 0;
- return esock_make_error_str(env, xres);
- }
-
- /* This transfers "ownership" of the *allocated* binary to an
- * erlang term (no need for an explicit free).
- */
- data = MKBIN(env, bufP);
-
- return esock_make_ok3(env, atom_false, data);
-
- }
+ if ((xres = recv_init_current_reader(env,
+ descP, recvRef)) != NULL) {
+ descP->rNumCnt = 0;
+ FREE_BIN(bufP);
+ return esock_make_error_str(env, xres);
+ }
- } else {
+ /* This transfers "ownership" of the *allocated* binary to an
+ * erlang term (no need for an explicit free).
+ */
+ data = MKBIN(env, bufP);
- /* Yes, we *do* need to continue reading */
+ SSDBG( descP,
+ ("SOCKET",
+ "recv_check_result -> [%d] "
+ "we are done for now - read more\r\n", toRead) );
- if ((xres = recv_init_current_reader(env,
- descP, recvRef)) != NULL) {
- descP->rNumCnt = 0;
- return esock_make_error_str(env, xres);
- }
-
- /* This transfers "ownership" of the *allocated* binary to an
- * erlang term (no need for an explicit free).
- */
- data = MKBIN(env, bufP);
-
- SSDBG( descP,
- ("SOCKET",
- "recv_check_result -> [%d] "
- "we are done for now - read more\r\n", toRead) );
-
- return esock_make_ok3(env, atom_false, data);
- }
+ return esock_make_ok3(env, atom_false, data);
} else {
@@ -13976,6 +13957,8 @@ ERL_NIF_TERM recv_check_result(ErlNifEnv* env,
/* +++ Error handling +++ */
+ FREE_BIN(bufP);
+
if (saveErrno == ECONNRESET) {
ERL_NIF_TERM res = esock_make_error(env, atom_closed);
@@ -14009,8 +13992,6 @@ ERL_NIF_TERM recv_check_result(ErlNifEnv* env,
(ERL_NIF_SELECT_STOP),
descP, NULL, recvRef);
- FREE_BIN(bufP);
-
return res;
} else if ((saveErrno == ERRNO_BLOCK) ||
@@ -14032,8 +14013,6 @@ ERL_NIF_TERM recv_check_result(ErlNifEnv* env,
SSDBG( descP,
("SOCKET", "recv_check_result -> SELECT res: %d\r\n", sres) );
- FREE_BIN(bufP);
-
return esock_make_error(env, esock_atom_eagain);
} else {
ERL_NIF_TERM res = esock_make_error_errno(env, saveErrno);
@@ -14043,8 +14022,6 @@ ERL_NIF_TERM recv_check_result(ErlNifEnv* env,
recv_error_current_reader(env, descP, sockRef, res);
- FREE_BIN(bufP);
-
return res;
}