Skip to content

Commit d3e976f

Browse files
miss-islingtonjelle-openaiJelleZijlstra
authored
[3.14] gh-159739: Release resources on interpreter startup error paths (GH-159752) (#159794)
gh-159739: Release resources on interpreter startup error paths (GH-159752) Release path-file read buffers on early return and the command string when an audit hook rejects execution. Backport to 3.15 and 3.14. (cherry picked from commit 36f7c13) Co-authored-by: Jelle Zijlstra <jelle@openai.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 4147bcc commit d3e976f

3 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix memory leaks during interpreter startup when a path configuration file is
2+
empty or too large, or when an audit hook rejects a command.

‎Modules/getpath.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,11 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
374374
size_t cb = fread(buffer, 1, MAX_FILE, fp);
375375
fclose(fp);
376376
if (!cb) {
377+
PyMem_Free(buffer);
377378
return r;
378379
}
379380
if (cb >= MAX_FILE) {
381+
PyMem_Free(buffer);
380382
Py_DECREF(r);
381383
PyErr_SetString(PyExc_MemoryError,
382384
"cannot read file larger than 32KB during initialization");

‎Modules/main.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ pymain_run_command(wchar_t *command)
252252
}
253253

254254
if (PySys_Audit("cpython.run_command", "O", unicode) < 0) {
255+
Py_DECREF(unicode);
255256
return pymain_exit_err_print();
256257
}
257258

0 commit comments

Comments
 (0)