Skip to content

Commit 75bac16

Browse files
committed
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.
1 parent dc1496e commit 75bac16

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

ext/standard/proc_open.c

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,17 @@ PHP_FUNCTION(proc_open)
11871187
}
11881188
}
11891189

1190+
if (1) {
1191+
RETVAL_RES(zend_register_resource(proc, le_proc_open));
1192+
} else {
1193+
exit_fail:
1194+
_php_free_envp(env);
1195+
if (command) {
1196+
efree(command);
1197+
}
1198+
RETVAL_FALSE;
1199+
}
1200+
11901201
#ifdef PHP_WIN32
11911202
free(cwdw);
11921203
free(cmdw);
@@ -1202,34 +1213,9 @@ PHP_FUNCTION(proc_open)
12021213
close(pty_slave_fd);
12031214
}
12041215
#endif
1205-
efree(descriptors);
1206-
ZVAL_RES(return_value, zend_register_resource(proc, le_proc_open));
1207-
return;
1208-
1209-
exit_fail:
12101216
if (descriptors) {
12111217
efree(descriptors);
12121218
}
1213-
_php_free_envp(env);
1214-
if (command) {
1215-
efree(command);
1216-
}
1217-
#ifdef PHP_WIN32
1218-
free(cwdw);
1219-
free(cmdw);
1220-
free(envpw);
1221-
#else
1222-
efree_argv(argv);
1223-
#endif
1224-
#if HAVE_OPENPTY
1225-
if (pty_master_fd != -1) {
1226-
close(pty_master_fd);
1227-
}
1228-
if (pty_slave_fd != -1) {
1229-
close(pty_slave_fd);
1230-
}
1231-
#endif
1232-
RETURN_FALSE;
12331219
}
12341220
/* }}} */
12351221

0 commit comments

Comments
 (0)