Skip to content

Commit af1e030

Browse files
authored
gh-159880: Fix handle leak in winreg when audit hook returns failure (GH-159881)
1 parent b124977 commit af1e030

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a key handle leak in :func:`winreg.CreateKey`,
2+
:func:`winreg.CreateKeyEx` and :func:`winreg.OpenKey` when the
3+
``winreg.OpenKey/result`` audit hook fails.

‎PC/winreg.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ winreg_CreateKey_impl(PyObject *module, HKEY key, const wchar_t *sub_key)
900900
}
901901
if (PySys_Audit("winreg.OpenKey/result", "n",
902902
(Py_ssize_t)retKey) < 0) {
903+
RegCloseKey(retKey);
903904
return NULL;
904905
}
905906
return retKey;
@@ -952,6 +953,7 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, const wchar_t *sub_key,
952953
}
953954
if (PySys_Audit("winreg.OpenKey/result", "n",
954955
(Py_ssize_t)retKey) < 0) {
956+
RegCloseKey(retKey);
955957
return NULL;
956958
}
957959
return retKey;
@@ -1398,6 +1400,7 @@ winreg_OpenKey_impl(PyObject *module, HKEY key, const wchar_t *sub_key,
13981400
}
13991401
if (PySys_Audit("winreg.OpenKey/result", "n",
14001402
(Py_ssize_t)retKey) < 0) {
1403+
RegCloseKey(retKey);
14011404
return NULL;
14021405
}
14031406
return retKey;

0 commit comments

Comments
 (0)