8000 bpo-34080: Fix memory leak on parsing error by vstinner · Pull Request #8242 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-34080: Fix memory leak on parsing error #8242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Only clear err->text in err_free()
  • Loading branch information
vstinner committed Jul 11, 2018
commit fdf73c9036aad00b0ca5a309734cd2a62329bab8
8 changes: 2 additions & 6 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static PyObject *run_mod(mod_ty, PyObject *, PyObject *, PyObject *,
PyCompilerFlags *, PyArena *);
static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *,
PyCompilerFlags *);
static void err_input(perrdetail *);
static void err_input(const perrdetail *);
static void err_free(perrdetail *);
static int PyRun_InteractiveOneObjectEx(FILE *, PyObject *, PyCompilerFlags *);

Expand Down Expand Up @@ -1331,7 +1331,7 @@ err_free(perrdetail *err)
/* Set the error appropriate to the given input error code (see errcode.h) */

static void
err_input(perrdetail *err)
err_input(const perrdetail *err)
{
PyObject *v, *w, *errtype, *errtext;
PyObject *msg_obj = NULL;
Expand Down Expand Up @@ -1447,10 +1447,6 @@ err_input(perrdetail *err)
Py_XDECREF(w);
cleanup:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goto cleanup is used even in branches when msg_obj is always NULL. Either replace them with return, or merge #8222.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything wrong with calling Py_XDECREF(msg_obj) when msg_obj is NULL. It's a common try/finally-like pattern applied to the C language. Moreover, I wrote this PR to fix a real memory leak, not to cleanup the code. Don't hesitate to propose a new PR once the memory leak is fixed, if you want to clean up the code further. I prefer to write the shortest PR to be able to backport it to all branches.

Py_XDECREF(msg_obj);
if (err->text != NULL) {
PyObject_Free(err->text);
err->text = NULL;
}
}


Expand Down
0