Fix Windows handles leak
Fixes thread and process handles leak when running and killing project
from editor (caused by a missing CloseHandle call) plus a potential leak
when calling OS_Windows::execute with p_blocking and !r_pipe.
The leak could be easily observed with a Handles counter in Task Manager
(or Performance Monitor) for the Godot editor process.
(cherry picked from commit b1e0da455b
)
This commit is contained in:
parent
209c6164f4
commit
771f1fe5c1
|
@ -2063,6 +2063,8 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments,
|
||||||
if (r_exitcode)
|
if (r_exitcode)
|
||||||
*r_exitcode = ret;
|
*r_exitcode = ret;
|
||||||
|
|
||||||
|
CloseHandle(pi.pi.hProcess);
|
||||||
|
CloseHandle(pi.pi.hThread);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
ProcessID pid = pi.pi.dwProcessId;
|
ProcessID pid = pi.pi.dwProcessId;
|
||||||
|
@ -2076,17 +2078,15 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments,
|
||||||
|
|
||||||
Error OS_Windows::kill(const ProcessID &p_pid) {
|
Error OS_Windows::kill(const ProcessID &p_pid) {
|
||||||
|
|
||||||
HANDLE h;
|
ERR_FAIL_COND_V(!process_map->has(p_pid), FAILED);
|
||||||
|
|
||||||
if (process_map->has(p_pid)) {
|
const PROCESS_INFORMATION pi = (*process_map)[p_pid].pi;
|
||||||
h = (*process_map)[p_pid].pi.hProcess;
|
process_map->erase(p_pid);
|
||||||
process_map->erase(p_pid);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
ERR_FAIL_COND_V(!process_map->has(p_pid), FAILED);
|
const int ret = TerminateProcess(pi.hProcess, 0);
|
||||||
};
|
|
||||||
|
|
||||||
int ret = TerminateProcess(h, 0);
|
CloseHandle(pi.hProcess);
|
||||||
|
CloseHandle(pi.hThread);
|
||||||
|
|
||||||
return ret != 0 ? OK : FAILED;
|
return ret != 0 ? OK : FAILED;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue