From aa6e540811bca3a11fedebafc41df8ddab426d15 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 3 Nov 2020 10:34:37 +0100 Subject: api: prevent double SetupDiDestroyDriverInfoList calls on error Signed-off-by: Simon Rozman --- api/adapter.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'api/adapter.c') 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); -- cgit v1.2.3-59-g8ed1b