Use a scope guard for more safety.
This commit is contained in:
parent
97eb69922f
commit
d56b2cc4c2
1 changed files with 3 additions and 5 deletions
|
@ -23,6 +23,7 @@
|
|||
#include <shlobj.h>
|
||||
#include <wtsapi32.h>
|
||||
|
||||
#include <Corrade/Containers/ScopeGuard.h>
|
||||
#include <Corrade/Utility/Directory.h>
|
||||
#include <Corrade/Utility/Unicode.h>
|
||||
|
||||
|
@ -52,6 +53,8 @@ auto MassBuilderManager::checkGameState() -> GameState {
|
|||
_gameState = GameState::Unknown;
|
||||
|
||||
if(WTSEnumerateProcessesW(WTS_CURRENT_SERVER_HANDLE, 0, 1, &process_infos, &process_count)) {
|
||||
Containers::ScopeGuard guard{process_infos, WTSFreeMemory};
|
||||
|
||||
for(unsigned long i = 0; i < process_count; ++i) {
|
||||
if(std::wcscmp(process_infos[i].pProcessName, L"MASS_Builder-Win64-Shipping.exe") == 0) {
|
||||
_gameState = GameState::Running;
|
||||
|
@ -63,11 +66,6 @@ auto MassBuilderManager::checkGameState() -> GameState {
|
|||
}
|
||||
}
|
||||
|
||||
if(process_infos != nullptr) {
|
||||
WTSFreeMemory(process_infos);
|
||||
process_infos = nullptr;
|
||||
}
|
||||
|
||||
return _gameState;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue