Skip to content

Commit 3032a68

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix GH-10885: Leaking stream_socket_server context
2 parents 2b0d29b + 122f128 commit 3032a68

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ PHP NEWS
5757
- SPL:
5858
. Fixed bug GH-10519 (Array Data Address Reference Issue). (Nathan Freeman)
5959

60+
- Standard:
61+
. Fixed bug GH-10885 (stream_socket_server context leaks). (ilutov)
62+
6063
16 Mar 2023, PHP 8.2.4
6164

6265
- Core:

ext/standard/streamsfuncs.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,6 @@ PHP_FUNCTION(stream_socket_server)
213213

214214
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
215215

216-
if (context) {
217-
GC_ADDREF(context->res);
218-
}
219-
220216
if (zerrno) {
221217
ZEND_TRY_ASSIGN_REF_LONG(zerrno, 0);
222218
}

ext/standard/tests/gh10885.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-10885: stream_socket_server context leaks
3+
--FILE--
4+
<?php
5+
$context = stream_context_create();
6+
debug_zval_dump($context);
7+
$server = @\stream_socket_server(
8+
'tcp://127.0.0.1:0',
9+
$errno,
10+
$errstr,
11+
\STREAM_SERVER_BIND | \STREAM_SERVER_LISTEN,
12+
$context,
13+
);
14+
debug_zval_dump($context);
15+
fclose($server);
16+
unset($server);
17+
debug_zval_dump($context);
18+
?>
19+
--EXPECTF--
20+
resource(%d) of type (stream-context) refcount(2)
21+
resource(%d) of type (stream-context) refcount(3)
22+
resource(%d) of type (stream-context) refcount(2)

0 commit comments

Comments
 (0)