qwindowsscreen.cpp: Fix memory leak of SetupDiGetClassDevs()
Use SetupDiDestroyDeviceInfoList() to delete the returned device information set. Fixes: QTBUG-127168 Pick-to: 6.7 6.5 Change-Id: I810e0f284e0d53d9b84d8c64022e566d6b740ab4 Reviewed-by: Pavel Dubsky <pavel.dubsky@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 5183ca14344c04015b32ef407e4cdad1b370c841) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
2623d34003
commit
e90a61ca49
@ -132,6 +132,18 @@ struct DiRegKeyHandleTraits
|
|||||||
|
|
||||||
using DiRegKeyHandle = QUniqueHandle<DiRegKeyHandleTraits>;
|
using DiRegKeyHandle = QUniqueHandle<DiRegKeyHandleTraits>;
|
||||||
|
|
||||||
|
struct DevInfoHandleTraits
|
||||||
|
{
|
||||||
|
using Type = HDEVINFO;
|
||||||
|
static Type invalidValue()
|
||||||
|
{
|
||||||
|
return reinterpret_cast<HDEVINFO>(INVALID_HANDLE_VALUE);
|
||||||
|
}
|
||||||
|
static bool close(Type handle) { return SetupDiDestroyDeviceInfoList(handle) == ERROR_SUCCESS; }
|
||||||
|
};
|
||||||
|
|
||||||
|
using DevInfoHandle = QUniqueHandle<DevInfoHandleTraits>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setMonitorDataFromSetupApi(QWindowsScreenData &data,
|
static void setMonitorDataFromSetupApi(QWindowsScreenData &data,
|
||||||
@ -181,13 +193,16 @@ static void setMonitorDataFromSetupApi(QWindowsScreenData &data,
|
|||||||
constexpr GUID GUID_DEVINTERFACE_MONITOR = {
|
constexpr GUID GUID_DEVINTERFACE_MONITOR = {
|
||||||
0xe6f07b5f, 0xee97, 0x4a90, { 0xb0, 0x76, 0x33, 0xf5, 0x7b, 0xf4, 0xea, 0xa7 }
|
0xe6f07b5f, 0xee97, 0x4a90, { 0xb0, 0x76, 0x33, 0xf5, 0x7b, 0xf4, 0xea, 0xa7 }
|
||||||
};
|
};
|
||||||
const HDEVINFO devInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_MONITOR, nullptr, nullptr,
|
const DevInfoHandle devInfo{ SetupDiGetClassDevs(
|
||||||
DIGCF_DEVICEINTERFACE);
|
&GUID_DEVINTERFACE_MONITOR, nullptr, nullptr, DIGCF_DEVICEINTERFACE) };
|
||||||
|
|
||||||
|
if (!devInfo.isValid())
|
||||||
|
continue;
|
||||||
|
|
||||||
SP_DEVICE_INTERFACE_DATA deviceInterfaceData{};
|
SP_DEVICE_INTERFACE_DATA deviceInterfaceData{};
|
||||||
deviceInterfaceData.cbSize = sizeof(deviceInterfaceData);
|
deviceInterfaceData.cbSize = sizeof(deviceInterfaceData);
|
||||||
|
|
||||||
if (!SetupDiOpenDeviceInterfaceW(devInfo, deviceName.monitorDevicePath, DIODI_NO_ADD,
|
if (!SetupDiOpenDeviceInterfaceW(devInfo.get(), deviceName.monitorDevicePath, DIODI_NO_ADD,
|
||||||
&deviceInterfaceData)) {
|
&deviceInterfaceData)) {
|
||||||
qCWarning(lcQpaScreen)
|
qCWarning(lcQpaScreen)
|
||||||
<< u"Unable to open monitor interface to %1:"_s.arg(data.deviceName)
|
<< u"Unable to open monitor interface to %1:"_s.arg(data.deviceName)
|
||||||
@ -196,7 +211,7 @@ static void setMonitorDataFromSetupApi(QWindowsScreenData &data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
DWORD requiredSize{ 0 };
|
DWORD requiredSize{ 0 };
|
||||||
if (SetupDiGetDeviceInterfaceDetailW(devInfo, &deviceInterfaceData, nullptr, 0,
|
if (SetupDiGetDeviceInterfaceDetailW(devInfo.get(), &deviceInterfaceData, nullptr, 0,
|
||||||
&requiredSize, nullptr)
|
&requiredSize, nullptr)
|
||||||
|| GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
|| GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||||
continue;
|
continue;
|
||||||
@ -207,7 +222,7 @@ static void setMonitorDataFromSetupApi(QWindowsScreenData &data,
|
|||||||
devicePath->cbSize = sizeof(std::remove_pointer_t<decltype(devicePath)>);
|
devicePath->cbSize = sizeof(std::remove_pointer_t<decltype(devicePath)>);
|
||||||
SP_DEVINFO_DATA deviceInfoData{};
|
SP_DEVINFO_DATA deviceInfoData{};
|
||||||
deviceInfoData.cbSize = sizeof(deviceInfoData);
|
deviceInfoData.cbSize = sizeof(deviceInfoData);
|
||||||
if (!SetupDiGetDeviceInterfaceDetailW(devInfo, &deviceInterfaceData, devicePath,
|
if (!SetupDiGetDeviceInterfaceDetailW(devInfo.get(), &deviceInterfaceData, devicePath,
|
||||||
requiredSize, nullptr, &deviceInfoData)) {
|
requiredSize, nullptr, &deviceInfoData)) {
|
||||||
qCDebug(lcQpaScreen) << u"Unable to get monitor metadata for %1:"_s.arg(data.deviceName)
|
qCDebug(lcQpaScreen) << u"Unable to get monitor metadata for %1:"_s.arg(data.deviceName)
|
||||||
<< QSystemError::windowsString();
|
<< QSystemError::windowsString();
|
||||||
@ -215,7 +230,7 @@ static void setMonitorDataFromSetupApi(QWindowsScreenData &data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const DiRegKeyHandle edidRegistryKey{ SetupDiOpenDevRegKey(
|
const DiRegKeyHandle edidRegistryKey{ SetupDiOpenDevRegKey(
|
||||||
devInfo, &deviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ) };
|
devInfo.get(), &deviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ) };
|
||||||
|
|
||||||
if (!edidRegistryKey.isValid())
|
if (!edidRegistryKey.isValid())
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user