File tree 5 files changed +56
-4
lines changed 5 files changed +56
-4
lines changed Original file line number Diff line number Diff line change @@ -270,9 +270,18 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown)
270
270
zval * zv ;
271
271
272
272
EG (flags ) |= EG_FLAGS_IN_RESOURCE_SHUTDOWN ;
273
+ #if ZEND_DEBUG
274
+ char * tmp = getenv ("AUTO_CLOSE_RESOURCE_LIST" );
275
+ if (tmp && !ZEND_ATOL (tmp )) {
276
+ goto skip_auto_closing_resource_list ;
277
+ }
278
+ #endif
273
279
zend_try {
274
280
zend_close_rsrc_list (& EG (regular_list ));
275
281
} zend_end_try ();
282
+ #if ZEND_DEBUG
283
+ skip_auto_closing_resource_list :
284
+ #endif
276
285
277
286
/* No PHP callback functions should be called after this point. */
278
287
EG (active ) = 0 ;
Original file line number Diff line number Diff line change @@ -230,6 +230,16 @@ void zend_close_rsrc_list(HashTable *ht)
230
230
231
231
void zend_destroy_rsrc_list (HashTable * ht )
232
232
{
233
+ #if ZEND_DEBUG
234
+ char * tmp = getenv ("AUTO_CLOSE_RESOURCE_LIST" );
235
+ if (tmp && !ZEND_ATOL (tmp )) {
236
+ if (!(HT_FLAGS (ht ) & HASH_FLAG_UNINITIALIZED )) {
237
+ pefree (HT_GET_DATA_ADDR (ht ), GC_FLAGS (ht ) & IS_ARRAY_PERSISTENT );
238
+ }
239
+ return ;
240
+ }
241
+ #endif
242
+
233
243
zend_hash_graceful_reverse_destroy (ht );
234
244
}
235
245
Original file line number Diff line number Diff line change @@ -213,10 +213,6 @@ PHP_FUNCTION(stream_socket_server)
213
213
214
214
context = php_stream_context_from_zval (zcontext , flags & PHP_FILE_NO_DEFAULT_CONTEXT );
215
215
216
- if (context ) {
217
- GC_ADDREF (context -> res );
218
- }
219
-
220
216
if (zerrno ) {
221
217
ZEND_TRY_ASSIGN_REF_LONG (zerrno , 0 );
222
218
}
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-10885: stream_socket_server context leaks
3
+ --ENV--
4
+ AUTO_CLOSE_RESOURCE_LIST=0
5
+ --FILE--
6
+ <?php
7
+ $ context = stream_context_create ();
8
+ $ server = @\stream_socket_server (
9
+ 'tcp://127.0.0.1:0 ' ,
10
+ $ errno ,
11
+ $ errstr ,
12
+ \STREAM_SERVER_BIND | \STREAM_SERVER_LISTEN ,
13
+ $ context ,
14
+ );
15
+ fclose ($ server );
16
+ ?>
17
+ ===DONE===
18
+ --EXPECT--
19
+ ===DONE===
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-10885: stream_socket_server context leaks
3
+ --ENV--
4
+ AUTO_CLOSE_RESOURCE_LIST=0
5
+ --FILE--
6
+ <?php
7
+ $ context = stream_context_create ();
8
+ $ result = @\stream_socket_server (
9
+ 'tcp://nonexistent:0 ' ,
10
+ $ errno ,
11
+ $ errstr ,
12
+ \STREAM_SERVER_BIND | \STREAM_SERVER_LISTEN ,
13
+ $ context ,
14
+ );
15
+ var_dump ($ result );
16
+ ?>
17
+ --EXPECT--
18
+ bool(false)
You can’t perform that action at this time.
0 commit comments