From: Nikita Popov Date: Thu, 14 May 2020 08:35:33 +0000 (+0200) Subject: Avoid duplicating the proc_open cleanup logic X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75bac167885b611ce981abdcbb21da7bb98a14c6;p=php Avoid duplicating the proc_open cleanup logic Use a slightly ugly "goto unreachable" pattern to share this code, so we don't have to duplicate cleanup logic for the success and the failure cases. --- diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index f1ecfd932e..e463e25157 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -1187,6 +1187,17 @@ PHP_FUNCTION(proc_open) } } + if (1) { + RETVAL_RES(zend_register_resource(proc, le_proc_open)); + } else { +exit_fail: + _php_free_envp(env); + if (command) { + efree(command); + } + RETVAL_FALSE; + } + #ifdef PHP_WIN32 free(cwdw); free(cmdw); @@ -1202,34 +1213,9 @@ PHP_FUNCTION(proc_open) close(pty_slave_fd); } #endif - efree(descriptors); - ZVAL_RES(return_value, zend_register_resource(proc, le_proc_open)); - return; - -exit_fail: if (descriptors) { efree(descriptors); } - _php_free_envp(env); - if (command) { - efree(command); - } -#ifdef PHP_WIN32 - free(cwdw); - free(cmdw); - free(envpw); -#else - efree_argv(argv); -#endif -#if HAVE_OPENPTY - if (pty_master_fd != -1) { - close(pty_master_fd); - } - if (pty_slave_fd != -1) { - close(pty_slave_fd); - } -#endif - RETURN_FALSE; } /* }}} */