Ensure cleanup on command failure

This commit is contained in:
Abdelrahman Said 2024-06-16 23:29:19 +01:00
parent 781a46713b
commit 92c2439b56

View File

@ -28,6 +28,7 @@ CMDResult run_command(CMDOutHandling out_handling, char *out_buf, u64 buf_size,
char cmd[CMD_BUF_LEN] = {0};
CMDError err = build_command_from_args(cmd, CMD_BUF_LEN, args);
if (err > SHELL_ERR_NO_ERROR) {
va_end(args);
return CMD_NO_EXIT(err);
}
@ -67,6 +68,8 @@ internal inline CMDResult execute_command(const char *cmd,
CMDError err = get_command_output(fp, out_handling, out_buf, buf_size);
if (err > SHELL_ERR_NO_ERROR) {
// Ensure process is closed on failure
wapp_shell_utils_pclose(fp);
return CMD_NO_EXIT(err);
}
@ -109,6 +112,8 @@ internal inline CMDError get_command_output(FILE *fp,
internal inline CMDError get_output_status(FILE *fp, i32 *status_out) {
#ifdef WAPP_PLATFORM_WINDOWS
if (!feof(fp)) {
// Ensure process is closed on failure
wapp_shell_utils_pclose(fp);
return SHELL_ERR_PROC_EXIT_FAIL;
}
#endif /* ifdef WAPP_PLATFORM_WINDOWS */