Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit ba3a8ac

Browse files
committed
Return E_CREATE_PROCESS_FAILED on CreateProcess failure
1 parent 9129a79 commit ba3a8ac

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Diff for: launcher/launcher.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum LauncherError : int {
1818
E_OS_ERROR = -1,
1919
E_APP_NOT_FOUND = -2,
2020
E_MODENGINE_NOT_FOUND = -3,
21+
E_CREATE_PROCESS_FAILED = -4,
2122
};
2223

2324
struct LaunchTargetParams {
@@ -55,7 +56,7 @@ namespace platform {
5556
std::wstring get_env_var(const std::wstring& name)
5657
{
5758
size_t buffer_size = GetEnvironmentVariableW(name.c_str(), nullptr, 0);
58-
wchar_t buffer[buffer_size + 1];
59+
auto* buffer = new wchar_t[buffer_size + 1];
5960

6061
std::wstring value;
6162

@@ -64,6 +65,8 @@ std::wstring get_env_var(const std::wstring& name)
6465
value.append(buffer, len);
6566
}
6667

68+
delete buffer;
69+
6770
return value;
6871
}
6972

@@ -75,16 +78,20 @@ void set_env_var(const std::wstring& name, const std::wstring& value)
7578
fs::path get_launcher_directory()
7679
{
7780
size_t buffer_size = GetModuleFileNameW(nullptr, nullptr, 0);
78-
wchar_t buffer[buffer_size + 1];
81+
auto* buffer = new wchar_t[buffer_size + 1];
82+
83+
fs::path path = fs::current_path();
7984

8085
if (buffer_size > 0) {
8186
size_t len = GetModuleFileNameW(nullptr, buffer, buffer_size + 1);
8287
fs::path launcher_path(std::wstring_view { buffer, len });
8388

84-
return launcher_path.parent_path();
89+
path = launcher_path.parent_path();
8590
}
8691

87-
return fs::current_path();
92+
delete buffer;
93+
94+
return path;
8895
}
8996

9097
}
@@ -207,9 +214,7 @@ int main()
207214
std::wstring cmd_str = app_cmd.native();
208215
size_t cmd_len = cmd_str.length();
209216

210-
wchar_t cmd[cmd_len + 1];
211-
cmd[cmd_len] = 0;
212-
217+
wchar_t cmd[cmd_len + 1] = {};
213218
wcsncpy_s(cmd, cmd_str.c_str(), cmd_len);
214219

215220
auto proc_flags = 0;
@@ -227,12 +232,15 @@ int main()
227232
fs::absolute(modengine_dll_path).native().c_str(),
228233
reinterpret_cast<PDETOUR_CREATE_PROCESS_ROUTINEW>(create_process_addr));
229234

235+
auto status = E_OK;
236+
230237
if (!success) {
231238
logger->error("Couldn't create process: {:x}", GetLastError());
239+
status = E_CREATE_PROCESS_FAILED;
232240
}
233241

234242
CloseHandle(pi.hProcess);
235243
CloseHandle(pi.hThread);
236244

237-
return E_OK;
245+
return status;
238246
}

0 commit comments

Comments
 (0)