Commit f91316ef authored by Christian Heimes's avatar Christian Heimes

Fix reference and memory leaks in _freeze_importlib

parent b5e7687f
...@@ -72,6 +72,7 @@ main(int argc, char *argv[]) ...@@ -72,6 +72,7 @@ main(int argc, char *argv[])
if (n < text_size) { if (n < text_size) {
fprintf(stderr, "read too short: got %ld instead of %ld bytes\n", fprintf(stderr, "read too short: got %ld instead of %ld bytes\n",
(long) n, (long) text_size); (long) n, (long) text_size);
free(text);
return 1; return 1;
} }
text[text_size] = '\0'; text[text_size] = '\0';
...@@ -86,6 +87,7 @@ main(int argc, char *argv[]) ...@@ -86,6 +87,7 @@ main(int argc, char *argv[])
code = Py_CompileStringExFlags(text, "<frozen importlib._bootstrap>", code = Py_CompileStringExFlags(text, "<frozen importlib._bootstrap>",
Py_file_input, NULL, 0); Py_file_input, NULL, 0);
free(text);
if (code == NULL) if (code == NULL)
goto error; goto error;
marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION); marshalled = PyMarshal_WriteObjectToString(code, Py_MARSHAL_VERSION);
...@@ -102,6 +104,7 @@ main(int argc, char *argv[]) ...@@ -102,6 +104,7 @@ main(int argc, char *argv[])
outfile = fopen(outpath, "w"); outfile = fopen(outpath, "w");
if (outfile == NULL) { if (outfile == NULL) {
fprintf(stderr, "cannot open '%s' for writing\n", outpath); fprintf(stderr, "cannot open '%s' for writing\n", outpath);
Py_DECREF(marshalled);
return 1; return 1;
} }
fprintf(outfile, "%s\n", header); fprintf(outfile, "%s\n", header);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment