From de7a6b1232ac863fb604cdec361a6b7e8e94384e Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Tue, 28 Jun 2016 11:32:41 +0800 Subject: [PATCH] MFH: Fixed fd leak (the origin commit can not be cherry-picked) --- ext/opcache/zend_file_cache.c | 2 ++ main/fastcgi.c | 2 +- sapi/cli/ps_title.c | 4 +++- sapi/phpdbg/phpdbg.c | 5 ++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index 31874124239..b8e9b1800b8 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -773,6 +773,7 @@ int zend_file_cache_script_store(zend_persistent_script *script, int in_shm) if (writev(fd, vec, 3) != (ssize_t)(sizeof(info) + script->size + info.str_size)) { zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot write to file '%s'\n", filename); zend_string_release((zend_string*)ZCG(mem)); + close(fd); efree(mem); unlink(filename); efree(filename); @@ -786,6 +787,7 @@ int zend_file_cache_script_store(zend_persistent_script *script, int in_shm) ) { zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot write to file '%s'\n", filename); zend_string_release((zend_string*)ZCG(mem)); + close(fd); efree(mem); unlink(filename); efree(filename); diff --git a/main/fastcgi.c b/main/fastcgi.c index 8fc7d6a968a..d2e1225246b 100644 --- a/main/fastcgi.c +++ b/main/fastcgi.c @@ -757,7 +757,7 @@ int fcgi_listen(const char *path, int backlog) #endif bind(listen_socket, (struct sockaddr *) &sa, sock_len) < 0 || listen(listen_socket, backlog) < 0) { - + close(listen_socket); fcgi_log(FCGI_ERROR, "Cannot bind/listen socket - [%d] %s.\n",errno, strerror(errno)); return -1; } diff --git a/sapi/cli/ps_title.c b/sapi/cli/ps_title.c index 2d95e494aa8..15ab0445d8c 100644 --- a/sapi/cli/ps_title.c +++ b/sapi/cli/ps_title.c @@ -224,8 +224,10 @@ char** save_ps_args(int argc, char** argv) for (i = 0; i < argc; i++) { new_argv[i] = strdup(argv[i]); - if (!new_argv[i]) + if (!new_argv[i]) { + free(new_argv); goto clobber_error; + } } new_argv[argc] = NULL; diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 68a164c4992..9b7993ddf04 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -1439,6 +1439,7 @@ phpdbg_main: case 'i': { /* set init file */ if (init_file) { free(init_file); + init_file = NULL; } init_file_len = strlen(php_optarg); @@ -1792,7 +1793,9 @@ phpdbg_main: /* initialize from file */ PHPDBG_G(flags) |= PHPDBG_IS_INITIALIZING; zend_try { - phpdbg_init(init_file, init_file_len, init_file_default); + if (init_file) { + phpdbg_init(init_file, init_file_len, init_file_default); + } if (bp_tmp) { PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT; phpdbg_string_init(bp_tmp);