Skip to content

Commit

Permalink
Fix GH-10885: Leaking stream_socket_server context
Browse files Browse the repository at this point in the history
`php_stream_context_set` already increases the refcount.

Closes GH-10886
  • Loading branch information
iluuu1994 committed Mar 20, 2023
1 parent 0d4d471 commit 122f128
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS
Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions ext/standard/streamsfuncs.c
Expand Up @@ -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);
}
Expand Down
22 changes: 22 additions & 0 deletions ext/standard/tests/gh10885.phpt
@@ -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)

0 comments on commit 122f128

Please sign in to comment.