Commit 36b98a46 authored by Neal Norwitz's avatar Neal Norwitz

Fix memory leaks

parent 5791a8ab
...@@ -404,7 +404,7 @@ builtin_compile(PyObject *self, PyObject *args) ...@@ -404,7 +404,7 @@ builtin_compile(PyObject *self, PyObject *args)
int dont_inherit = 0; int dont_inherit = 0;
int supplied_flags = 0; int supplied_flags = 0;
PyCompilerFlags cf; PyCompilerFlags cf;
PyObject *result, *cmd, *tmp = NULL; PyObject *result = NULL, *cmd, *tmp = NULL;
int length; int length;
if (!PyArg_ParseTuple(args, "Oss|ii:compile", &cmd, &filename, if (!PyArg_ParseTuple(args, "Oss|ii:compile", &cmd, &filename,
...@@ -427,7 +427,7 @@ builtin_compile(PyObject *self, PyObject *args) ...@@ -427,7 +427,7 @@ builtin_compile(PyObject *self, PyObject *args)
if ((size_t)length != strlen(str)) { if ((size_t)length != strlen(str)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"compile() expected string without null bytes"); "compile() expected string without null bytes");
return NULL; goto cleanup;
} }
if (strcmp(startstr, "exec") == 0) if (strcmp(startstr, "exec") == 0)
...@@ -439,7 +439,7 @@ builtin_compile(PyObject *self, PyObject *args) ...@@ -439,7 +439,7 @@ builtin_compile(PyObject *self, PyObject *args)
else { else {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"compile() arg 3 must be 'exec' or 'eval' or 'single'"); "compile() arg 3 must be 'exec' or 'eval' or 'single'");
return NULL; goto cleanup;
} }
if (supplied_flags & if (supplied_flags &
...@@ -447,7 +447,7 @@ builtin_compile(PyObject *self, PyObject *args) ...@@ -447,7 +447,7 @@ builtin_compile(PyObject *self, PyObject *args)
{ {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"compile(): unrecognised flags"); "compile(): unrecognised flags");
return NULL; goto cleanup;
} }
/* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */ /* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */
...@@ -455,6 +455,7 @@ builtin_compile(PyObject *self, PyObject *args) ...@@ -455,6 +455,7 @@ builtin_compile(PyObject *self, PyObject *args)
PyEval_MergeCompilerFlags(&cf); PyEval_MergeCompilerFlags(&cf);
} }
result = Py_CompileStringFlags(str, filename, start, &cf); result = Py_CompileStringFlags(str, filename, start, &cf);
cleanup:
Py_XDECREF(tmp); Py_XDECREF(tmp);
return result; return result;
} }
...@@ -580,8 +581,10 @@ builtin_eval(PyObject *self, PyObject *args) ...@@ -580,8 +581,10 @@ builtin_eval(PyObject *self, PyObject *args)
cf.cf_flags |= PyCF_SOURCE_IS_UTF8; cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
} }
#endif #endif
if (PyString_AsStringAndSize(cmd, &str, NULL)) if (PyString_AsStringAndSize(cmd, &str, NULL)) {
Py_XDECREF(tmp);
return NULL; return NULL;
}
while (*str == ' ' || *str == '\t') while (*str == ' ' || *str == '\t')
str++; str++;
......
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