Skip to content

Commit e286845

Browse files
miss-islingtonaisk
andauthored
[3.15] gh-159880: Fix handle leak in winreg when audit hook returns failure (GH-159881) (GH-159889)
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 7b2a168 commit e286845

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
@@ -903,6 +903,7 @@ winreg_CreateKey_impl(PyObject *module, HKEY key, const wchar_t *sub_key)
903903
}
904904
if (PySys_Audit("winreg.OpenKey/result", "n",
905905
(Py_ssize_t)retKey) < 0) {
906+
RegCloseKey(retKey);
906907
return NULL;
907908
}
908909
return retKey;
@@ -955,6 +956,7 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, const wchar_t *sub_key,
955956
}
956957
if (PySys_Audit("winreg.OpenKey/result", "n",
957958
(Py_ssize_t)retKey) < 0) {
959+
RegCloseKey(retKey);
958960
return NULL;
959961
}
960962
return retKey;
@@ -1401,6 +1403,7 @@ winreg_OpenKey_impl(PyObject *module, HKEY key, const wchar_t *sub_key,
14011403
}
14021404
if (PySys_Audit("winreg.OpenKey/result", "n",
14031405
(Py_ssize_t)retKey) < 0) {
1406+
RegCloseKey(retKey);
14041407
return NULL;
14051408
}
14061409
return retKey;

0 commit comments

Comments
 (0)