summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-06-14 14:44:22 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-06-17 20:11:15 +0200
commit7e335f290b1c3bc771097f01c715d1dc5f115077 (patch)
tree77cd1c2e8f93de31914dca440e14112d517db893 /src/corelib
parent6b36e783521993df8de6477c789aa26c38803656 (diff)
QWinSettings: use QScopeGuard to RegCloseKey()
RAII rulez. Change-Id: I32bc070ae3074f782a1695bcf2079de0fc19597b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qsettings_win.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp
index 979b37a0be..b9ab84d580 100644
--- a/src/corelib/io/qsettings_win.cpp
+++ b/src/corelib/io/qsettings_win.cpp
@@ -43,6 +43,7 @@
#include "qlist.h"
#include "qmap.h"
#include "qdebug.h"
+#include "qscopeguard.h"
#include <qt_windows.h>
// See "Accessing an Alternate Registry View" at:
@@ -487,14 +488,14 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa
if (handle == 0)
return false;
+ const auto closeKey = qScopeGuard([handle] { RegCloseKey(handle); });
+
// get the size and type of the value
DWORD dataType;
DWORD dataSize;
LONG res = RegQueryValueEx(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, &dataType, 0, &dataSize);
- if (res != ERROR_SUCCESS) {
- RegCloseKey(handle);
+ if (res != ERROR_SUCCESS)
return false;
- }
// workaround for rare cases where trailing '\0' are missing in registry
if (dataType == REG_SZ || dataType == REG_EXPAND_SZ)
@@ -506,10 +507,8 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa
QByteArray data(dataSize, 0);
res = RegQueryValueEx(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, 0,
reinterpret_cast<unsigned char*>(data.data()), &dataSize);
- if (res != ERROR_SUCCESS) {
- RegCloseKey(handle);
+ if (res != ERROR_SUCCESS)
return false;
- }
switch (dataType) {
case REG_EXPAND_SZ:
@@ -578,7 +577,6 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa
break;
}
- RegCloseKey(handle);
return true;
}