From 75612a4b4f2b494aaa7bb34a4dbfdaba80447885 Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Fri, 18 Dec 2015 19:53:56 +0100 Subject: [PATCH] Fix resource leak/fix broken file open check Also marking the error path as unlikely while I am on it. Fixes coverity CID154482. Change-Id: I069fa7753e364ff1b8a4449b7008dfa8aee73de5 Reviewed-by: Marc Mutz Reviewed-by: Robin Burchell --- .../devicediscovery/qdevicediscovery_static.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/platformsupport/devicediscovery/qdevicediscovery_static.cpp b/src/platformsupport/devicediscovery/qdevicediscovery_static.cpp index de2f3415af..4bf7508b2f 100644 --- a/src/platformsupport/devicediscovery/qdevicediscovery_static.cpp +++ b/src/platformsupport/devicediscovery/qdevicediscovery_static.cpp @@ -120,15 +120,17 @@ QStringList QDeviceDiscoveryStatic::scanConnectedDevices() bool QDeviceDiscoveryStatic::checkDeviceType(const QString &device) { int fd = QT_OPEN(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); - if (!fd) { + if (Q_UNLIKELY(fd == -1)) { qWarning() << "Device discovery cannot open device" << device; return false; } qCDebug(lcDD) << "doing static device discovery for " << device; - if ((m_types & Device_DRM) && device.contains(QString::fromLatin1(QT_DRM_DEVICE_PREFIX))) + if ((m_types & Device_DRM) && device.contains(QString::fromLatin1(QT_DRM_DEVICE_PREFIX))) { + QT_CLOSE(fd); return true; + } long bitsAbs[LONG_FIELD_SIZE(ABS_CNT)]; long bitsKey[LONG_FIELD_SIZE(KEY_CNT)];