]> granicus.if.org Git - python/commitdiff
Fix memory leaks
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 27 Nov 2005 20:38:31 +0000 (20:38 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 27 Nov 2005 20:38:31 +0000 (20:38 +0000)
Python/bltinmodule.c

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