Skip to content

Commit c0ffe0f

Browse files
miss-islingtonaisk
andauthored
[3.14] gh-159880: Fix handle leak in winreg when audit hook returns failure (GH-159881) (GH-159890)
gh-159880: Fix handle leak in winreg when audit hook returns failure (GH-159881) (cherry picked from commit af1e030) Co-authored-by: An Long <aisk@users.noreply.github.com>
1 parent bae32d6 commit c0ffe0f

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
@@ -944,6 +944,7 @@ winreg_CreateKey_impl(PyObject *module, HKEY key, const wchar_t *sub_key)
944944
}
945945
if (PySys_Audit("winreg.OpenKey/result", "n",
946946
(Py_ssize_t)retKey) < 0) {
947+
RegCloseKey(retKey);
947948
return NULL;
948949
}
949950
return retKey;
@@ -996,6 +997,7 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, const wchar_t *sub_key,
996997
}
997998
if (PySys_Audit("winreg.OpenKey/result", "n",
998999
(Py_ssize_t)retKey) < 0) {
1000+
RegCloseKey(retKey);
9991001
return NULL;
10001002
}
10011003
return retKey;
@@ -1442,6 +1444,7 @@ winreg_OpenKey_impl(PyObject *module, HKEY key, const wchar_t *sub_key,
14421444
}
14431445
if (PySys_Audit("winreg.OpenKey/result", "n",
14441446
(Py_ssize_t)retKey) < 0) {
1447+
RegCloseKey(retKey);
14451448
return NULL;
14461449
}
14471450
return retKey;

0 commit comments

Comments
 (0)