fix: ImHex not always exiting when forwarder is killed

This commit is contained in:
WerWolv
2026-01-07 17:12:58 +01:00
parent 550fe8e4aa
commit a0a049a920

View File

@@ -94,6 +94,12 @@ int launchExecutable() {
// Ensure the read handle to stdout is not inherited
::SetHandleInformation(hChildStdoutRead, HANDLE_FLAG_INHERIT, 0);
// Create a job object to ensure the child process is terminated when this process exits
auto hJob = ::CreateJobObjectW(nullptr, nullptr);
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info {};
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
::SetInformationJobObject(hJob, JobObjectExtendedLimitInformation, &info, sizeof(info));
// Set up the STARTUPINFO structure for the child process
STARTUPINFOW si;
::ZeroMemory(&si, sizeof(STARTUPINFOW));
@@ -113,7 +119,7 @@ int launchExecutable() {
nullptr, // Process security attributes
nullptr, // Thread security attributes
TRUE, // Inherit handles
0, // Creation flags
CREATE_SUSPENDED, // Creation flags
nullptr, // Environment
nullptr, // Current directory
&si, // STARTUPINFO
@@ -126,6 +132,20 @@ int launchExecutable() {
return EXIT_FAILURE;
}
if (::AssignProcessToJobObject(hJob, pi.hProcess)) {
if (::ResumeThread(pi.hThread) == -1) {
::TerminateProcess(pi.hProcess, EXIT_FAILURE);
::CloseHandle(hChildStdinRead);
::CloseHandle(hChildStdinWrite);
::CloseHandle(hChildStdoutRead);
::CloseHandle(hChildStdoutWrite);
::CloseHandle(pi.hProcess);
::CloseHandle(pi.hThread);
return EXIT_FAILURE;
}
}
// Close handles that the child inherited
::CloseHandle(hChildStdinRead);
::CloseHandle(hChildStdoutWrite);