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

Skip to content

Commit 96f628f

Browse files
committed
Fix reference and memory leaks in _freeze_importlib
1 parent 1f34729 commit 96f628f

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

Modules/_freeze_importlib.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ main(int argc, char *argv[])
7272
if (n < text_size) {
7373
fprintf(stderr, "read too short: got %ld instead of %ld bytes\n",
7474
(long) n, (long) text_size);
75+
free(text);
7576
return 1;
7677
}
7778
text[text_size] = '\0';
@@ -86,6 +87,7 @@ main(int argc, char *argv[])
8687

8788
code = Py_CompileStringExFlags(text, "<frozen importlib._bootstrap>",
8889
Py_file_input, NULL, 0);
90+
free(text);
8991
if (code == NULL)
9092
goto error;
9193
marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION);
@@ -102,6 +104,7 @@ main(int argc, char *argv[])
102104
outfile = fopen(outpath, "w");
103105
if (outfile == NULL) {
104106
fprintf(stderr, "cannot open '%s' for writing\n", outpath);
107+
Py_DECREF(marshalled);
105108
return 1;
106109
}
107110
fprintf(outfile, "%s\n", header);

0 commit comments

Comments
 (0)