Skip to content

Commit 83f4f04

Browse files
authored
fix leaking certificate issue (#265)
* fix leaking certificate issue * mypy * mypy ignore
1 parent bbf2208 commit 83f4f04

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

certifi/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
This module returns the installation location of cacert.pem or its contents.
66
"""
77
import sys
8+
import atexit
9+
10+
def exit_cacert_ctx() -> None:
11+
_CACERT_CTX.__exit__(None, None, None) # type: ignore[union-attr]
812

913

1014
if sys.version_info >= (3, 11):
@@ -35,6 +39,7 @@ def where() -> str:
3539
# we will also store that at the global level as well.
3640
_CACERT_CTX = as_file(files("certifi").joinpath("cacert.pem"))
3741
_CACERT_PATH = str(_CACERT_CTX.__enter__())
42+
atexit.register(exit_cacert_ctx)
3843

3944
return _CACERT_PATH
4045

@@ -70,6 +75,7 @@ def where() -> str:
7075
# we will also store that at the global level as well.
7176
_CACERT_CTX = get_path("certifi", "cacert.pem")
7277
_CACERT_PATH = str(_CACERT_CTX.__enter__())
78+
atexit.register(exit_cacert_ctx)
7379

7480
return _CACERT_PATH
7581

0 commit comments

Comments
 (0)