From 2b5a298f825f7b61ab4372734f7726b2d8228b44 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Wed, 26 Apr 2017 13:17:06 +0200 Subject: [PATCH] Return the return value of uv_spawn if not zero Fixes #38 --- php_uv.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/php_uv.c b/php_uv.c index a3e4e67..80d423b 100644 --- a/php_uv.c +++ b/php_uv.c @@ -5209,7 +5209,7 @@ PHP_FUNCTION(uv_spawn) zval *zloop, *args, *env, *zoptions = NULL, *zstdio = NULL, *value; char **command_args, **zenv; zend_string *command, *cwd; - int uid = 0, gid = 0, stdio_count = 0; + int uid = 0, gid = 0, stdio_count = 0, ret; long flags = 0; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -5331,19 +5331,24 @@ PHP_FUNCTION(uv_spawn) options.uid = uid; options.gid = gid; - proc = (php_uv_t *)emalloc(sizeof(php_uv_t)); - PHP_UV_INIT_ZVALS(proc); - php_uv_cb_init(&cb, proc, &fci, &fcc, PHP_UV_PROC_CLOSE_CB); - TSRMLS_SET_CTX(proc->thread_ctx); + proc = (php_uv_t *) emalloc(sizeof(php_uv_t)); + ret = uv_spawn(loop, &proc->uv.process, &options); - proc->type = IS_UV_PROCESS; - proc->uv.process.data = proc; + if (ret) { + efree(proc); + RETURN_LONG(ret); + } else { + PHP_UV_INIT_ZVALS(proc); + php_uv_cb_init(&cb, proc, &fci, &fcc, PHP_UV_PROC_CLOSE_CB); + TSRMLS_SET_CTX(proc->thread_ctx); - proc->resource_id = zend_register_resource(proc, uv_resource_handle); - ZVAL_RES(return_value, proc->resource_id); - zval_copy_ctor(return_value); + proc->type = IS_UV_PROCESS; + proc->uv.process.data = proc; - uv_spawn(loop, &proc->uv.process, &options); + proc->resource_id = zend_register_resource(proc, uv_resource_handle); + ZVAL_RES(return_value, proc->resource_id); + zval_copy_ctor(return_value); + } if (zenv != NULL) { char **p = zenv;