From a2ab5c8296975dc21735340043a03e3c964038ad Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 8 May 2017 12:07:22 +0200 Subject: [PATCH] Fix #44 - prepare 0.2.1 --- package.xml | 11 +++++------ php_uv.c | 17 +++++++++++------ php_uv.h | 2 +- tests/400-tcp_bind.phpt | 4 +--- tests/400-tcp_bind6.phpt | 4 +--- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/package.xml b/package.xml index 3e1fa30..be843d7 100644 --- a/package.xml +++ b/package.xml @@ -10,11 +10,11 @@ bobwei9@hotmail.com yes - 2017-05-07 - + 2017-05-08 + - 0.2.0 - 0.2.0 + 0.2.1 + 0.2.1 beta @@ -22,8 +22,7 @@ PHP License -- Move from resource handles to object handles -- Various smaller fixes +- Fix memory leak when closing diff --git a/php_uv.c b/php_uv.c index ac6ce98..370f74e 100644 --- a/php_uv.c +++ b/php_uv.c @@ -1242,10 +1242,11 @@ void static destruct_uv(zend_object *obj) if (uv_cancel(&uv->uv.req) == UV_EBUSY) { ++GC_REFCOUNT(obj); } - } else if (!uv_is_closing(&uv->uv.handle)) { + clean_uv_handle(uv); + } else { php_uv_close(uv); + /* cleaning happens in close_cb */ } - clean_uv_handle(uv); } void static php_uv_free_write_req(write_req_t *wr) { @@ -2039,16 +2040,16 @@ static void php_uv_close_cb(uv_handle_t *handle) php_uv_t *uv = (php_uv_t *) handle->data; TSRMLS_FETCH_FROM_CTX(uv->thread_ctx); - if (!PHP_UV_IS_DTORED(uv)) { + if (uv->callback[PHP_UV_CLOSE_CB]) { ZVAL_OBJ(¶ms[0], (zend_object *) uv); php_uv_do_callback2(&retval, uv, params, 1, PHP_UV_CLOSE_CB TSRMLS_CC); zval_ptr_dtor(&retval); - - /* manually clean the uv handle to avoid default dtor handling */ - clean_uv_handle(uv); } + /* manually clean the uv handle as dtor will not be called anymore here */ + clean_uv_handle(uv); + PHP_UV_DEBUG_OBJ_DEL_REFCOUNT(uv_close_cb, uv); OBJ_RELEASE(&uv->std); } @@ -2059,13 +2060,17 @@ static inline zend_bool php_uv_is_handle_referenced(php_uv_t *uv) { return (ce == uv_signal_ce || ce == uv_timer_ce || ce == uv_idle_ce || ce == uv_udp_ce || ce == uv_tcp_ce || ce == uv_tty_ce || ce == uv_pipe_ce || ce == uv_prepare_ce || ce == uv_check_ce || ce == uv_poll_ce || ce == uv_fs_poll_ce) ? uv_is_active(&uv->uv.handle) : (ce == uv_async_ce); } +/* uv handle must not be cleaned or closed before called */ static void php_uv_close(php_uv_t *uv) { + ZEND_ASSERT(!uv_is_closing(&uv->uv.handle)); + if (!php_uv_is_handle_referenced(uv)) { ++GC_REFCOUNT(&uv->std); PHP_UV_DEBUG_OBJ_ADD_REFCOUNT(php_uv_close, uv); } uv_close(&uv->uv.handle, php_uv_close_cb); + PHP_UV_SKIP_DTOR(uv); } diff --git a/php_uv.h b/php_uv.h index 03607e0..6f828b9 100755 --- a/php_uv.h +++ b/php_uv.h @@ -3,7 +3,7 @@ #define PHP_UV_H #define PHP_UV_EXTNAME "uv" -#define PHP_UV_VERSION "0.2.0" +#define PHP_UV_VERSION "0.2.1" #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/tests/400-tcp_bind.phpt b/tests/400-tcp_bind.phpt index 1e32c19..83478aa 100644 --- a/tests/400-tcp_bind.phpt +++ b/tests/400-tcp_bind.phpt @@ -10,9 +10,7 @@ uv_listen($tcp, 100, function($server){ uv_read_start($client, function($socket, $nread, $buffer) use ($server) { echo $buffer . PHP_EOL; uv_close($socket); - uv_close($server, function() use ($server) { - uv_unref($server); - }); + uv_close($server); }); }); diff --git a/tests/400-tcp_bind6.phpt b/tests/400-tcp_bind6.phpt index 664f104..4fda557 100644 --- a/tests/400-tcp_bind6.phpt +++ b/tests/400-tcp_bind6.phpt @@ -10,9 +10,7 @@ uv_listen($tcp,100, function($server) { uv_read_start($client, function($socket, $nread, $buffer) use ($server) { echo $buffer . PHP_EOL; uv_close($socket); - uv_close($server,function() use ($server) { - uv_unref($server); - }); + uv_close($server); }); });