10000 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
DECREF the original error message.
  • Loading branch information
ericsnowcurrently committed Feb 3, 2018
commit e982d873129877788b755765b81542b0155e0ab8
22 changes: 20 additions & 2 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ typedef struct _sharedexception {
char *msg;
} _sharedexception;

static void
_sharedexception_free(_sharedexception *exc) {
PyMem_Free(exc->msg);
PyMem_Free(exc);
}

static _sharedexception *
_get_shared_exception(void)
{
Expand All @@ -162,7 +168,18 @@ _get_shared_exception(void)
err->msg = "unable to format exception";
return err;
}
err->msg = (char *)PyUnicode_AsUTF8(msg);
const char *errmsg = PyUnicode_AsUTF8(msg);
if (errmsg == NULL) {
err->msg = "unable to encode exception";
}
err->msg = PyMem_Malloc(strlen(errmsg)+1);
if (err->msg == NULL) {
Py_DECREF(msg);
err->msg = "MemoryError: out of memory copying error message";
return err;
}
strcpy(err->msg, errmsg);
Py_DECREF(msg);
if (err->msg == NULL) {
err->msg = "unable to encode exception";
}
Expand Down Expand Up @@ -1079,6 +1096,7 @@ channelid_new(PyTypeObject *cls, PyObject *args, PyObject *kwds)
"'send' and 'recv' cannot both be False");
return NULL;
}

int end = 0;
if (send == 1) {
if (recv == 0 || recv == -1) {
Expand Down Expand Up @@ -1471,7 +1489,7 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
// Propagate any exception out to the caller.
if (exc != NULL) {
_apply_shared_exception(exc);
PyMem_Free(exc);
_sharedexception_free(exc);
}
else if (result != 0) {
// We were unable to allocate a shared exception.
Expand Down
0