api: prevent double SetupDiDestroyDriverInfoList calls on error
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
19d6227c1d
commit
aa6e540811
@ -1197,6 +1197,7 @@ SelectDriver(
|
|||||||
Result = LOG_LAST_ERROR(L"Failed building driver info list");
|
Result = LOG_LAST_ERROR(L"Failed building driver info list");
|
||||||
goto cleanupDriverInstallationLock;
|
goto cleanupDriverInstallationLock;
|
||||||
}
|
}
|
||||||
|
BOOL DestroyDriverInfoListOnCleanup = TRUE;
|
||||||
FILETIME DriverDate = { 0 };
|
FILETIME DriverDate = { 0 };
|
||||||
DWORDLONG DriverVersion = 0;
|
DWORDLONG DriverVersion = 0;
|
||||||
HDEVINFO DevInfoExistingAdapters = INVALID_HANDLE_VALUE;
|
HDEVINFO DevInfoExistingAdapters = INVALID_HANDLE_VALUE;
|
||||||
@ -1227,7 +1228,8 @@ SelectDriver(
|
|||||||
if (DevInfoExistingAdapters == INVALID_HANDLE_VALUE)
|
if (DevInfoExistingAdapters == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
Result = LOG_LAST_ERROR(L"Failed to get present adapters");
|
Result = LOG_LAST_ERROR(L"Failed to get present adapters");
|
||||||
goto cleanupDrvInfoDetailData;
|
HeapFree(ModuleHeap, 0, DrvInfoDetailData);
|
||||||
|
goto cleanupExistingAdapters;
|
||||||
}
|
}
|
||||||
_Analysis_assume_(DevInfoExistingAdapters != NULL);
|
_Analysis_assume_(DevInfoExistingAdapters != NULL);
|
||||||
DisableAllOurAdapters(DevInfoExistingAdapters, &ExistingAdapters);
|
DisableAllOurAdapters(DevInfoExistingAdapters, &ExistingAdapters);
|
||||||
@ -1252,14 +1254,13 @@ SelectDriver(
|
|||||||
DriverVersion = DrvInfoData.DriverVersion;
|
DriverVersion = DrvInfoData.DriverVersion;
|
||||||
next:
|
next:
|
||||||
HeapFree(ModuleHeap, 0, DrvInfoDetailData);
|
HeapFree(ModuleHeap, 0, DrvInfoDetailData);
|
||||||
continue;
|
|
||||||
cleanupDrvInfoDetailData:
|
|
||||||
HeapFree(ModuleHeap, 0, DrvInfoDetailData);
|
|
||||||
goto cleanupExistingAdapters;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DriverVersion)
|
if (DriverVersion)
|
||||||
|
{
|
||||||
|
DestroyDriverInfoListOnCleanup = FALSE;
|
||||||
goto cleanupExistingAdapters;
|
goto cleanupExistingAdapters;
|
||||||
|
}
|
||||||
|
|
||||||
WCHAR RandomTempSubDirectory[MAX_PATH];
|
WCHAR RandomTempSubDirectory[MAX_PATH];
|
||||||
if ((Result = CreateTemporaryDirectory(RandomTempSubDirectory)) != ERROR_SUCCESS)
|
if ((Result = CreateTemporaryDirectory(RandomTempSubDirectory)) != ERROR_SUCCESS)
|
||||||
@ -1307,6 +1308,7 @@ SelectDriver(
|
|||||||
*RebootRequired = *RebootRequired || UpdateRebootRequired;
|
*RebootRequired = *RebootRequired || UpdateRebootRequired;
|
||||||
|
|
||||||
SetupDiDestroyDriverInfoList(DevInfo, DevInfoData, SPDIT_COMPATDRIVER);
|
SetupDiDestroyDriverInfoList(DevInfo, DevInfoData, SPDIT_COMPATDRIVER);
|
||||||
|
DestroyDriverInfoListOnCleanup = FALSE;
|
||||||
DevInstallParams->Flags |= DI_ENUMSINGLEINF;
|
DevInstallParams->Flags |= DI_ENUMSINGLEINF;
|
||||||
if (wcsncpy_s(DevInstallParams->DriverPath, _countof(DevInstallParams->DriverPath), InfStorePath, _TRUNCATE) ==
|
if (wcsncpy_s(DevInstallParams->DriverPath, _countof(DevInstallParams->DriverPath), InfStorePath, _TRUNCATE) ==
|
||||||
STRUNCATE)
|
STRUNCATE)
|
||||||
@ -1325,6 +1327,7 @@ SelectDriver(
|
|||||||
Result = LOG_LAST_ERROR(L"Failed rebuilding driver info list");
|
Result = LOG_LAST_ERROR(L"Failed rebuilding driver info list");
|
||||||
goto cleanupDelete;
|
goto cleanupDelete;
|
||||||
}
|
}
|
||||||
|
DestroyDriverInfoListOnCleanup = TRUE;
|
||||||
SP_DRVINFO_DATA_W DrvInfoData = { .cbSize = sizeof(SP_DRVINFO_DATA_W) };
|
SP_DRVINFO_DATA_W DrvInfoData = { .cbSize = sizeof(SP_DRVINFO_DATA_W) };
|
||||||
if (!SetupDiEnumDriverInfoW(DevInfo, DevInfoData, SPDIT_COMPATDRIVER, 0, &DrvInfoData))
|
if (!SetupDiEnumDriverInfoW(DevInfo, DevInfoData, SPDIT_COMPATDRIVER, 0, &DrvInfoData))
|
||||||
{
|
{
|
||||||
@ -1337,6 +1340,7 @@ SelectDriver(
|
|||||||
goto cleanupDelete;
|
goto cleanupDelete;
|
||||||
}
|
}
|
||||||
Result = ERROR_SUCCESS;
|
Result = ERROR_SUCCESS;
|
||||||
|
DestroyDriverInfoListOnCleanup = FALSE;
|
||||||
|
|
||||||
cleanupDelete:
|
cleanupDelete:
|
||||||
DeleteFileW(CatPath);
|
DeleteFileW(CatPath);
|
||||||
@ -1357,7 +1361,7 @@ cleanupExistingAdapters:
|
|||||||
}
|
}
|
||||||
if (DevInfoExistingAdapters != INVALID_HANDLE_VALUE)
|
if (DevInfoExistingAdapters != INVALID_HANDLE_VALUE)
|
||||||
SetupDiDestroyDeviceInfoList(DevInfoExistingAdapters);
|
SetupDiDestroyDeviceInfoList(DevInfoExistingAdapters);
|
||||||
if (Result != ERROR_SUCCESS)
|
if (DestroyDriverInfoListOnCleanup)
|
||||||
SetupDiDestroyDriverInfoList(DevInfo, DevInfoData, SPDIT_COMPATDRIVER);
|
SetupDiDestroyDriverInfoList(DevInfo, DevInfoData, SPDIT_COMPATDRIVER);
|
||||||
cleanupDriverInstallationLock:
|
cleanupDriverInstallationLock:
|
||||||
NamespaceReleaseMutex(DriverInstallationLock);
|
NamespaceReleaseMutex(DriverInstallationLock);
|
||||||
|
Loading…
Reference in New Issue
Block a user