]> granicus.if.org Git - php/commitdiff
Avoid duplicating the proc_open cleanup logic
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 14 May 2020 08:35:33 +0000 (10:35 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 14 May 2020 08:35:33 +0000 (10:35 +0200)
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.

ext/standard/proc_open.c

index f1ecfd932e8c2e632ec5190c036043817b436c3b..e463e2515718d5025798475916fef87f055d2b15 100644 (file)
@@ -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;
 }
 /* }}} */