8000 bpo-32604: Fix memory leaks in the new _xxsubinterpreters module. by ericsnowcurrently · Pull Request #5507 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-32604: Fix memory leaks in the new _xxsubinterpreters module. #5507

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

Merged
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
Next Next commit
Move the RunFailedError definition down.
  • Loading branch information
ericsnowcurrently committed Feb 3, 2018
commit ac7bad55356103302af46255bc00bdba497a4860
62 changes: 34 additions & 28 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ _coerce_id(PyObject *id)
return cid;
}


/* data-sharing-specific code ***********************************************/

struct _sharednsitem {
Expand Down Expand Up @@ -282,45 +283,26 @@ _sharedexception_bind(PyObject *exctype, PyObject *exc, PyObject *tb)
return err;
}

static PyObject * RunFailedError;

static int
interp_exceptions_init(PyObject *ns)
{
// XXX Move the exceptions into per-module memory?

// An uncaught exception came out of interp_run_string().
RunFailedError = PyErr_NewException("_xxsubinterpreters.RunFailedError",
PyExc_RuntimeError, NULL);
if (RunFailedError == NULL) {
return -1;
}
if (PyDict_SetItemString(ns, "RunFailedError", RunFailedError) != 0) {
return -1;
}

return 0;
}

static void
_sharedexception_apply(_sharedexception *exc)
_sharedexception_apply(_sharedexception *exc, PyObject *wrapperclass)
{
if (exc->name != NULL) {
if (exc->msg != NULL) {
PyErr_Format(RunFailedError, "%s: %s", exc->name, exc->msg);
PyErr_Format(wrapperclass, "%s: %s", exc->name, exc->msg);
}
else {
PyErr_SetString(RunFailedError, exc->name);
PyErr_SetString(wrapperclass, exc->name);
}
}
else if (exc->msg != NULL) {
PyErr_SetString(RunFailedError, exc->msg);
PyErr_SetString(wrapperclass, exc->msg);
}
else {
PyErr_SetNone(RunFailedError);
PyErr_SetNone(wrapperclass);
}
}


/* channel-specific code ****************************************************/

static PyObject *ChannelError;
Expand Down Expand Up @@ -1639,7 +1621,30 @@ static PyTypeObject ChannelIDtype = {
NULL, /* tp_new */
};

/* interpreter-specific functions *******************************************/

/* interpreter-specific code ************************************************/

static PyObject * RunFailedError = NULL;

static int
interp_exceptions_init(PyObject *ns)
{
// XXX Move the exceptions into per-module memory?

if (RunFailedError == NULL) {
// An uncaught exception came out of interp_run_string().
RunFailedError = PyErr_NewException("_xxsubinterpreters.RunFailedError",
PyExc_RuntimeError, NULL);
if (RunFailedError == NULL) {
return -1;
}
if (PyDict_SetItemString(ns, "RunFailedError", RunFailedError) != 0) {
return -1;
}
}

return 0;
}

static PyInterpreterState *
_look_up(PyObject *requested_id)
Expand Down Expand Up @@ -1748,11 +1753,12 @@ _run_script(PyInterpreterState *interp, const char *codestr,
if (sharedexc == NULL) {
fprintf(stderr, "RunFailedError: script raised an uncaught exception");
PyErr_Clear();
sharedexc = NULL;
}
else {
assert(!PyErr_Occurred());
*exc = sharedexc;
}
*exc = sharedexc;
return -1;
}

Expand Down Expand Up @@ -1784,7 +1790,7 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,

// Propagate any exception out to the caller.
if (exc != NULL) {
_sharedexception_apply(exc);
_sharedexception_apply(exc, RunFailedError);
_sharedexception_free(exc);
}
else if (result != 0) {
Expand Down
0