Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d50c3f3

Browse files
committed
Issue #21393: random.c: on Windows, close the hCryptProv handle at exit
1 parent cb2ad80 commit d50c3f3

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Python/random.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ static int _Py_HashSecret_Initialized = 0;
1515
#endif
1616

1717
#ifdef MS_WINDOWS
18-
/* This handle is never explicitly released. Instead, the operating
19-
system will release it when the process terminates. */
2018
static HCRYPTPROV hCryptProv = 0;
2119

2220
static int
@@ -298,7 +296,12 @@ _PyRandom_Init(void)
298296
void
299297
_PyRandom_Fini(void)
300298
{
301-
#ifndef MS_WINDOWS
299+
#ifdef MS_WINDOWS
300+
if (hCryptProv) {
301+
CloseHandle(hCryptProv);
302+
hCryptProv = 0;
303+
}
304+
#else
302305
dev_urandom_close();
303306
#endif
304307
}

0 commit comments

Comments
 (0)