diff options
author | Simon Rozman <simon@rozman.si> | 2020-11-03 10:34:37 +0100 |
---|---|---|
committer | Simon Rozman <simon@rozman.si> | 2020-11-03 10:40:09 +0100 |
commit | aa6e540811bca3a11fedebafc41df8ddab426d15 (patch) | |
tree | a34728a3f6a91d855649c66f67d59ae6c4abd453 /api | |
parent | api: rundll32: repair token spawning semantics (diff) | |
download | wintun-aa6e540811bca3a11fedebafc41df8ddab426d15.tar.xz wintun-aa6e540811bca3a11fedebafc41df8ddab426d15.zip |
api: prevent double SetupDiDestroyDriverInfoList calls on error
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'api')
-rw-r--r-- | api/adapter.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/api/adapter.c b/api/adapter.c index 86eef0f..2b56dca 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -1197,6 +1197,7 @@ SelectDriver( Result = LOG_LAST_ERROR(L"Failed building driver info list"); goto cleanupDriverInstallationLock; } + BOOL DestroyDriverInfoListOnCleanup = TRUE; FILETIME DriverDate = { 0 }; DWORDLONG DriverVersion = 0; HDEVINFO DevInfoExistingAdapters = INVALID_HANDLE_VALUE; @@ -1227,7 +1228,8 @@ SelectDriver( if (DevInfoExistingAdapters == INVALID_HANDLE_VALUE) { Result = LOG_LAST_ERROR(L"Failed to get present adapters"); - goto cleanupDrvInfoDetailData; + HeapFree(ModuleHeap, 0, DrvInfoDetailData); + goto cleanupExistingAdapters; } _Analysis_assume_(DevInfoExistingAdapters != NULL); DisableAllOurAdapters(DevInfoExistingAdapters, &ExistingAdapters); @@ -1252,14 +1254,13 @@ SelectDriver( DriverVersion = DrvInfoData.DriverVersion; next: HeapFree(ModuleHeap, 0, DrvInfoDetailData); - continue; - cleanupDrvInfoDetailData: - HeapFree(ModuleHeap, 0, DrvInfoDetailData); - goto cleanupExistingAdapters; } if (DriverVersion) + { + DestroyDriverInfoListOnCleanup = FALSE; goto cleanupExistingAdapters; + } WCHAR RandomTempSubDirectory[MAX_PATH]; if ((Result = CreateTemporaryDirectory(RandomTempSubDirectory)) != ERROR_SUCCESS) @@ -1307,6 +1308,7 @@ SelectDriver( *RebootRequired = *RebootRequired || UpdateRebootRequired; SetupDiDestroyDriverInfoList(DevInfo, DevInfoData, SPDIT_COMPATDRIVER); + DestroyDriverInfoListOnCleanup = FALSE; DevInstallParams->Flags |= DI_ENUMSINGLEINF; if (wcsncpy_s(DevInstallParams->DriverPath, _countof(DevInstallParams->DriverPath), InfStorePath, _TRUNCATE) == STRUNCATE) @@ -1325,6 +1327,7 @@ SelectDriver( Result = LOG_LAST_ERROR(L"Failed rebuilding driver info list"); goto cleanupDelete; } + DestroyDriverInfoListOnCleanup = TRUE; SP_DRVINFO_DATA_W DrvInfoData = { .cbSize = sizeof(SP_DRVINFO_DATA_W) }; if (!SetupDiEnumDriverInfoW(DevInfo, DevInfoData, SPDIT_COMPATDRIVER, 0, &DrvInfoData)) { @@ -1337,6 +1340,7 @@ SelectDriver( goto cleanupDelete; } Result = ERROR_SUCCESS; + DestroyDriverInfoListOnCleanup = FALSE; cleanupDelete: DeleteFileW(CatPath); @@ -1357,7 +1361,7 @@ cleanupExistingAdapters: } if (DevInfoExistingAdapters != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(DevInfoExistingAdapters); - if (Result != ERROR_SUCCESS) + if (DestroyDriverInfoListOnCleanup) SetupDiDestroyDriverInfoList(DevInfo, DevInfoData, SPDIT_COMPATDRIVER); cleanupDriverInstallationLock: NamespaceReleaseMutex(DriverInstallationLock); |