Skip to content

Commit

Permalink
fix leaking certificate issue (#265)
Browse files Browse the repository at this point in the history
* fix leaking certificate issue

* mypy

* mypy ignore
  • Loading branch information
luccabb authored Jan 30, 2024
1 parent bbf2208 commit 83f4f04
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions certifi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
This module returns the installation location of cacert.pem or its contents.
"""
import sys
import atexit

def exit_cacert_ctx() -> None:
_CACERT_CTX.__exit__(None, None, None) # type: ignore[union-attr]


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

return _CACERT_PATH

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

return _CACERT_PATH

Expand Down

0 comments on commit 83f4f04

Please sign in to comment.