mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-26 20:14:47 +01:00
Merge branch 'fix-memory-leak' of https://github.com/Ezaki113/php-uv
Also fix memory leaks in general when closing without previous explicit stop
This commit is contained in:
commit
e2a6bcddae
23
php_uv.c
23
php_uv.c
@ -2096,7 +2096,29 @@ static void php_uv_close_cb(uv_handle_t *handle)
|
||||
|
||||
PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_close_cb, uv->resource_id);
|
||||
|
||||
switch (uv->type) {
|
||||
case IS_UV_SIGNAL:
|
||||
case IS_UV_TIMER:
|
||||
case IS_UV_IDLE:
|
||||
case IS_UV_UDP:
|
||||
case IS_UV_TCP:
|
||||
case IS_UV_TTY:
|
||||
case IS_UV_PIPE:
|
||||
case IS_UV_PREPARE:
|
||||
case IS_UV_CHECK:
|
||||
case IS_UV_POLL:
|
||||
case IS_UV_FS_POLL:
|
||||
if (!uv_is_active(&uv->uv.handle)) {
|
||||
break;
|
||||
}
|
||||
case IS_UV_ASYNC:
|
||||
--GC_REFCOUNT(uv->resource_id);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
uv->in_free = -1;
|
||||
zend_list_close(uv->resource_id);
|
||||
|
||||
zval_ptr_dtor(¶ms[0]); /* call destruct_uv */
|
||||
}
|
||||
@ -5624,6 +5646,7 @@ PHP_FUNCTION(uv_async_init)
|
||||
|
||||
ZVAL_RES(return_value, uv->resource_id);
|
||||
GC_REFCOUNT(uv->resource_id)++;
|
||||
PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_async_init, uv->resource_id);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
22
tests/006-uv_async_init-no-memory-leak.phpt
Normal file
22
tests/006-uv_async_init-no-memory-leak.phpt
Normal file
@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
Check uv_async has no memory leak
|
||||
--FILE--
|
||||
<?php
|
||||
$m = memory_get_usage();
|
||||
|
||||
$loop = uv_loop_new();
|
||||
|
||||
$async = uv_async_init($loop, static function ($async) {
|
||||
uv_close($async);
|
||||
});
|
||||
uv_async_send($async);
|
||||
|
||||
unset($async);
|
||||
|
||||
uv_run($loop, UV::RUN_DEFAULT);
|
||||
uv_loop_delete($loop);
|
||||
unset($loop);
|
||||
|
||||
echo memory_get_usage() - $m, PHP_EOL;
|
||||
--EXPECTF--
|
||||
0
|
Loading…
Reference in New Issue
Block a user