summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-08-05 16:42:40 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-08-05 16:42:55 +0200
commit25d849d40b42ff8384beda0e8b93ef63fae11739 (patch)
tree0d1e983ed2b5e67dc9029397685028c21b780ddb /ext
parent643145b59d03ee9c92390078d545c4c45baca69b (diff)
parent3b86be23e6641c2a298bf381d39346177223176a (diff)
downloadphp-git-25d849d40b42ff8384beda0e8b93ef63fae11739.tar.gz
Merge branch 'PHP-7.4'
* PHP-7.4: Fix memory leak on socket_sendmsg() / socket_recvmsg() error
Diffstat (limited to 'ext')
-rw-r--r--ext/sockets/sendrecvmsg.c15
-rw-r--r--ext/sockets/tests/socket_sendrecvmsg_error.phpt15
2 files changed, 22 insertions, 8 deletions
diff --git a/ext/sockets/sendrecvmsg.c b/ext/sockets/sendrecvmsg.c
index 9e97cf00e2..f03fdb0c63 100644
--- a/ext/sockets/sendrecvmsg.c
+++ b/ext/sockets/sendrecvmsg.c
@@ -192,14 +192,13 @@ PHP_FUNCTION(socket_sendmsg)
res = sendmsg(php_sock->bsd_socket, msghdr, (int)flags);
if (res != -1) {
- zend_llist_destroy(allocations);
- efree(allocations);
-
- RETURN_LONG((zend_long)res);
+ RETVAL_LONG((zend_long)res);
} else {
PHP_SOCKET_ERROR(php_sock, "error in sendmsg", errno);
- RETURN_FALSE;
+ RETVAL_FALSE;
}
+
+ allocations_dispose(&allocations);
}
PHP_FUNCTION(socket_recvmsg)
@@ -246,7 +245,6 @@ PHP_FUNCTION(socket_recvmsg)
/* we don;t need msghdr anymore; free it */
msghdr = NULL;
- allocations_dispose(&allocations);
zval_ptr_dtor(zmsg);
if (!err.has_error) {
@@ -257,14 +255,15 @@ PHP_FUNCTION(socket_recvmsg)
/* no need to destroy/free zres -- it's NULL in this circumstance */
assert(zres == NULL);
}
+ RETVAL_LONG((zend_long)res);
} else {
SOCKETS_G(last_error) = errno;
php_error_docref(NULL, E_WARNING, "Error in recvmsg [%d]: %s",
errno, sockets_strerror(errno));
- RETURN_FALSE;
+ RETVAL_FALSE;
}
- RETURN_LONG((zend_long)res);
+ allocations_dispose(&allocations);
}
PHP_FUNCTION(socket_cmsg_space)
diff --git a/ext/sockets/tests/socket_sendrecvmsg_error.phpt b/ext/sockets/tests/socket_sendrecvmsg_error.phpt
new file mode 100644
index 0000000000..8700b4184c
--- /dev/null
+++ b/ext/sockets/tests/socket_sendrecvmsg_error.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Error during socket_sendmsg() or socket_recvmsg()
+--FILE--
+<?php
+
+$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+socket_sendmsg($socket, [], -1);
+$message = ['controllen' => 1];
+socket_recvmsg($socket, $message, -1);
+
+?>
+--EXPECTF--
+Warning: socket_sendmsg(): error in sendmsg [%d]: %a in %s on line %d
+
+Warning: socket_recvmsg(): Error in recvmsg [%d]: %a in %s on line %d