From 122f1287a07c43d79c2c934d79d67e3fe194470b 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. Closes GH-10886 --- NEWS | 3 +++ ext/standard/streamsfuncs.c | 4 ---- ext/standard/tests/gh10885.phpt | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 ext/standard/tests/gh10885.phpt diff --git a/NEWS b/NEWS index 85bb5c240b7..01cf4ac6317 100644 --- a/NEWS +++ b/NEWS @@ -49,6 +49,9 @@ PHP NEWS - SPL: . Fixed bug GH-10519 (Array Data Address Reference Issue). (Nathan Freeman) +- Standard: + . Fixed bug GH-10885 (stream_socket_server context leaks). (ilutov) + 16 Mar 2023, PHP 8.1.17 - Core: diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 13f3ead5aec..188bcee8854 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 00000000000..167b832aa25 --- /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)