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:
Bob Weinand 2017-02-28 18:22:45 +01:00
commit e2a6bcddae
2 changed files with 45 additions and 0 deletions

View File

@ -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(&params[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);
}
/* }}} */

View 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