summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-02-24 16:54:06 (GMT)
committerGitHub <noreply@github.com>2022-02-24 16:54:06 (GMT)
commit4dc746310bd37ad6b381f9176acd167d445f4385 (patch)
tree414abfb60866c640ea403888d9c7356e2e120f4b /Tools/scripts
parent042f31da552c19054acd3ef7bb6cfd857bce172b (diff)
downloadcpython-4dc746310bd37ad6b381f9176acd167d445f4385.zip
cpython-4dc746310bd37ad6b381f9176acd167d445f4385.tar.gz
cpython-4dc746310bd37ad6b381f9176acd167d445f4385.tar.bz2
bpo-46430: Fix memory leak in interned strings of deep-frozen modules (GH-31549)
Diffstat (limited to 'Tools/scripts')
-rw-r--r--Tools/scripts/deepfreeze.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py
index 0edf3af..b62be37 100644
--- a/Tools/scripts/deepfreeze.py
+++ b/Tools/scripts/deepfreeze.py
@@ -110,6 +110,7 @@ class Printer:
self.hits, self.misses = 0, 0
self.patchups: list[str] = []
self.deallocs: list[str] = []
+ self.interns: list[str] = []
self.write('#include "Python.h"')
self.write('#include "internal/pycore_gc.h"')
self.write('#include "internal/pycore_code.h"')
@@ -279,7 +280,7 @@ class Printer:
self.write(f".co_cellvars = {co_cellvars},")
self.write(f".co_freevars = {co_freevars},")
self.deallocs.append(f"_PyStaticCode_Dealloc(&{name});")
- self.patchups.append(f"_PyStaticCode_InternStrings(&{name});")
+ self.interns.append(f"_PyStaticCode_InternStrings(&{name});")
return f"& {name}.ob_base"
def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:
@@ -446,6 +447,9 @@ def generate(args: list[str], output: TextIO) -> None:
with printer.block(f"void\n_Py_Deepfreeze_Fini(void)"):
for p in printer.deallocs:
printer.write(p)
+ with printer.block(f"void\n_Py_Deepfreeze_Init(void)"):
+ for p in printer.interns:
+ printer.write(p)
if verbose:
print(f"Cache hits: {printer.hits}, misses: {printer.misses}")