File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Expand file tree Collapse file tree 4 files changed +45
-1
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 @@ -241,14 +241,20 @@ PHP_FUNCTION(stream_socket_server)
241
241
} else if (errstr ) {
242
242
zend_string_release_ex (errstr , 0 );
243
243
}
244
- RETURN_FALSE ;
244
+ RETVAL_FALSE ;
245
+ goto exit ;
245
246
}
246
247
247
248
if (errstr ) {
248
249
zend_string_release_ex (errstr , 0 );
249
250
}
250
251
251
252
php_stream_to_zval (stream , return_value );
253
+
254
+ exit :
255
+ if (zcontext ) {
256
+ zval_ptr_dtor (zcontext );
257
+ }
252
258
}
253
259
/* }}} */
254
260
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===
You can’t perform that action at this time.
0 commit comments