Skip to content

Commit e4237d9

Browse files
committed
Merge conditions and close the newly opened key handle in CreateKeyEx
1 parent 68a5549 commit e4237d9

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

PC/winreg.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -961,15 +961,13 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, const wchar_t *sub_key,
961961
PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx");
962962
return NULL;
963963
}
964-
if (!exist_ok) {
965-
if (disposition == REG_OPENED_EXISTING_KEY) {
966-
PyErr_SetFromWindowsErrWithFunction(ERROR_ALREADY_EXISTS, "CreateKeyEx");
967-
if (retKey != key) {
968-
// This is not a predefined key and needs to be closed.
969-
RegCloseKey(key);
970-
}
971-
return NULL;
964+
if (!exist_ok && disposition == REG_OPENED_EXISTING_KEY) {
965+
PyErr_SetFromWindowsErrWithFunction(ERROR_ALREADY_EXISTS, "CreateKeyEx");
966+
if (retKey != key) {
967+
// This is not a predefined key and needs to be closed.
968+
RegCloseKey(retKey);
972969
}
970+
return NULL;
973971
}
974972
if (PySys_Audit("winreg.OpenKey/result", "n",
975973
(Py_ssize_t)retKey) < 0) {

0 commit comments

Comments
 (0)