diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-05-14 10:35:33 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-05-14 10:35:33 +0200 |
commit | 75bac167885b611ce981abdcbb21da7bb98a14c6 (patch) | |
tree | 31e87097c86cf7a05dabb1142f1871f9fba7c3c9 /ext | |
parent | dc1496e4a34343fc875b43b814d886f1371aa34d (diff) | |
download | php-git-75bac167885b611ce981abdcbb21da7bb98a14c6.tar.gz |
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.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/standard/proc_open.c | 36 |
1 files changed, 11 insertions, 25 deletions
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; } /* }}} */ |