summaryrefslogtreecommitdiffstats
path: root/base/win/registry.cc
diff options
context:
space:
mode:
authorwfh@chromium.org <wfh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-15 07:12:02 +0000
committerwfh@chromium.org <wfh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-15 07:12:02 +0000
commit4e53cb3b926bde438d2175dcb006dd534e5becab (patch)
tree026c8cbdafc34773491c3f6a85a7156539b528b4 /base/win/registry.cc
parentc089f7d283c62b6ca895303436281b1c8981dcbd (diff)
downloadchromium_src-4e53cb3b926bde438d2175dcb006dd534e5becab.zip
chromium_src-4e53cb3b926bde438d2175dcb006dd534e5becab.tar.gz
chromium_src-4e53cb3b926bde438d2175dcb006dd534e5becab.tar.bz2
Fix issue where RegKey data would be changed if Open() or Create() calls fail.
BUG=373486 R=cpu@chromium.org Review URL: https://codereview.chromium.org/288063002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270613 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/win/registry.cc')
-rw-r--r--base/win/registry.cc33
1 files changed, 23 insertions, 10 deletions
diff --git a/base/win/registry.cc b/base/win/registry.cc
index 8bfe432..7330d08 100644
--- a/base/win/registry.cc
+++ b/base/win/registry.cc
@@ -69,11 +69,15 @@ LONG RegKey::Create(HKEY rootkey, const wchar_t* subkey, REGSAM access) {
LONG RegKey::CreateWithDisposition(HKEY rootkey, const wchar_t* subkey,
DWORD* disposition, REGSAM access) {
DCHECK(rootkey && subkey && access && disposition);
- Close();
-
+ HKEY subhkey = NULL;
LONG result = RegCreateKeyEx(rootkey, subkey, 0, NULL,
- REG_OPTION_NON_VOLATILE, access, NULL, &key_,
+ REG_OPTION_NON_VOLATILE, access, NULL, &subhkey,
disposition);
+ if (result == ERROR_SUCCESS) {
+ Close();
+ key_ = subhkey;
+ }
+
return result;
}
@@ -82,17 +86,25 @@ LONG RegKey::CreateKey(const wchar_t* name, REGSAM access) {
HKEY subkey = NULL;
LONG result = RegCreateKeyEx(key_, name, 0, NULL, REG_OPTION_NON_VOLATILE,
access, NULL, &subkey, NULL);
- Close();
+ if (result == ERROR_SUCCESS) {
+ Close();
+
+ key_ = subkey;
+ }
- key_ = subkey;
return result;
}
LONG RegKey::Open(HKEY rootkey, const wchar_t* subkey, REGSAM access) {
DCHECK(rootkey && subkey && access);
- Close();
+ HKEY subhkey = NULL;
+
+ LONG result = RegOpenKeyEx(rootkey, subkey, 0, access, &subhkey);
+ if (result == ERROR_SUCCESS) {
+ Close();
+ key_ = subhkey;
+ }
- LONG result = RegOpenKeyEx(rootkey, subkey, 0, access, &key_);
return result;
}
@@ -103,9 +115,10 @@ LONG RegKey::OpenKey(const wchar_t* relative_key_name, REGSAM access) {
// We have to close the current opened key before replacing it with the new
// one.
- Close();
-
- key_ = subkey;
+ if (result == ERROR_SUCCESS) {
+ Close();
+ key_ = subkey;
+ }
return result;
}