diff options
| author | Jeremy Rimpo <jeremy.rimpo@servermonkey.com> | 2017-11-02 16:05:09 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-02 16:05:09 -0500 |
| commit | b2d0abe0e4a264bc82739cfbbe2861f896642b49 (patch) | |
| tree | 9bf10dc181c927a7e767c052697b2429db1b1bd8 /src | |
| parent | 55a65b16cc8491978c5a0b4c1f4ae44cc460de8f (diff) | |
| parent | 00af56f7c7e8b233ba6a466b23bb907ba9ca4648 (diff) | |
Merge pull request #120 from Silarn/mainline_dev
Fix remaining handle leaks
Diffstat (limited to 'src')
| -rw-r--r-- | src/organizercore.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/organizercore.cpp b/src/organizercore.cpp index f77d7356..26b726e9 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -104,17 +104,20 @@ static std::wstring getProcessName(DWORD processId) HANDLE process = ::OpenProcess(PROCESS_QUERY_INFORMATION, false, processId);
wchar_t buffer[MAX_PATH];
+ wchar_t *fileName = L"unknown";
+
+ if (process == nullptr) return fileName;
+
if (::GetProcessImageFileNameW(process, buffer, MAX_PATH) != 0) {
- wchar_t *fileName = wcsrchr(buffer, L'\\');
+ fileName = wcsrchr(buffer, L'\\');
if (fileName == nullptr) {
fileName = buffer;
} else {
fileName += 1;
}
- return fileName;
- } else {
- return std::wstring(L"unknown");
}
+ ::CloseHandle(process);
+ return fileName;
}
static void startSteam(QWidget *widget)
@@ -363,6 +366,12 @@ bool OrganizerCore::testForSteam() PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processIDs[i]);
if (process != nullptr) {
+
+ ON_BLOCK_EXIT([&]() {
+ if (process != INVALID_HANDLE_VALUE)
+ ::CloseHandle(process);
+ });
+
HMODULE module;
DWORD ignore;
@@ -1267,7 +1276,7 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode) std::wstring processName = getProcessName(processes[i]);
if (!boost::starts_with(processName, L"ModOrganizer.exe")) {
currentProcess = processes[i];
- if (processHandle != INVALID_HANDLE_VALUE)
+ if (processHandle != INVALID_HANDLE_VALUE && processHandle != handle)
::CloseHandle(processHandle);
processHandle = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, currentProcess);
found = true;
|
