Skip to content

Commit

Permalink
Factorize resource release after CreateProcess()
Browse files Browse the repository at this point in the history
Free the wide characters string in all cases before checking for errors.
  • Loading branch information
rom1v committed Nov 15, 2021
1 parent fd4ec78 commit 9cb8766
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/src/sys/win/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ sc_process_execute_p(const char *const argv[], HANDLE *handle,
goto error_close_stderr;
}

if (!CreateProcessW(NULL, wide, NULL, NULL, TRUE, 0, NULL, NULL, &si,
&pi)) {
free(wide);

BOOL ok = CreateProcessW(NULL, wide, NULL, NULL, TRUE, 0, NULL, NULL, &si,
&pi);
free(wide);
if (!ok) {
if (GetLastError() == ERROR_FILE_NOT_FOUND) {
ret = SC_PROCESS_ERROR_MISSING_BINARY;
}
Expand All @@ -115,7 +115,6 @@ sc_process_execute_p(const char *const argv[], HANDLE *handle,
CloseHandle(stderr_write_handle);
}

free(wide);
*handle = pi.hProcess;

return SC_PROCESS_SUCCESS;
Expand Down

0 comments on commit 9cb8766

Please sign in to comment.