Fix GH-10885: Leaking stream_socket_server context

`php_stream_context_set` already increases the refcount.

Closes GH-10886
This commit is contained in:
Ilija Tovilo 2023-03-20 12:08:13 +01:00
parent 0d4d471847
commit 122f1287a0
No known key found for this signature in database
GPG Key ID: A4F5D403F118200A
3 changed files with 25 additions and 4 deletions

3
NEWS
View File

@ -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:

View File

@ -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);
}

View File

@ -0,0 +1,22 @@
--TEST--
GH-10885: stream_socket_server context leaks
--FILE--
<?php
$context = stream_context_create();
debug_zval_dump($context);
$server = @\stream_socket_server(
'tcp://127.0.0.1:0',
$errno,
$errstr,
\STREAM_SERVER_BIND | \STREAM_SERVER_LISTEN,
$context,
);
debug_zval_dump($context);
fclose($server);
unset($server);
debug_zval_dump($context);
?>
--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)