From a0a4d9d0d32dbd1f0ecb20c7ee77768b255e4885 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Mon, 20 Mar 2023 12:08:13 +0100 Subject: [PATCH] Fix GH-10885: Leaking stream_socket_server context `php_stream_context_set` already increases the refcount. --- ext/standard/streamsfuncs.c | 4 ---- ext/standard/tests/gh10885.phpt | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 ext/standard/tests/gh10885.phpt diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 13f3ead5aecf8..188bcee885481 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -213,10 +213,6 @@ PHP_FUNCTION(stream_socket_server) context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); - if (context) { - GC_ADDREF(context->res); - } - if (zerrno) { ZEND_TRY_ASSIGN_REF_LONG(zerrno, 0); } diff --git a/ext/standard/tests/gh10885.phpt b/ext/standard/tests/gh10885.phpt new file mode 100644 index 0000000000000..167b832aa25ad --- /dev/null +++ b/ext/standard/tests/gh10885.phpt @@ -0,0 +1,22 @@ +--TEST-- +GH-10885: stream_socket_server context leaks +--FILE-- + +--EXPECTF-- +resource(%d) of type (stream-context) refcount(2) +resource(%d) of type (stream-context) refcount(3) +resource(%d) of type (stream-context) refcount(2)