Commit 72cf6a8c authored by Neal Norwitz's avatar Neal Norwitz

Fix memory leaks reported by valgrind

parent 23b5918f
...@@ -961,7 +961,7 @@ MPZ_powm(PyObject *self, PyObject *args) ...@@ -961,7 +961,7 @@ MPZ_powm(PyObject *self, PyObject *args)
{ {
PyObject *base, *exp, *mod; PyObject *base, *exp, *mod;
mpzobject *mpzbase = NULL, *mpzexp = NULL, *mpzmod = NULL; mpzobject *mpzbase = NULL, *mpzexp = NULL, *mpzmod = NULL;
mpzobject *z; mpzobject *z = NULL;
int tstres; int tstres;
...@@ -975,10 +975,15 @@ MPZ_powm(PyObject *self, PyObject *args) ...@@ -975,10 +975,15 @@ MPZ_powm(PyObject *self, PyObject *args)
Py_XDECREF(mpzbase); Py_XDECREF(mpzbase);
Py_XDECREF(mpzexp); Py_XDECREF(mpzexp);
Py_XDECREF(mpzmod); Py_XDECREF(mpzmod);
Py_XDECREF(z);
return NULL; return NULL;
} }
if ((tstres=mpz_cmp_ui(&mpzexp->mpz, (unsigned long int)0)) == 0) { if ((tstres=mpz_cmp_ui(&mpzexp->mpz, (unsigned long int)0)) == 0) {
Py_DECREF(mpzbase);
Py_DECREF(mpzexp);
Py_DECREF(mpzmod);
Py_DECREF(z);
Py_INCREF(mpz_value_one); Py_INCREF(mpz_value_one);
return (PyObject *)mpz_value_one; return (PyObject *)mpz_value_one;
} }
...@@ -987,6 +992,7 @@ MPZ_powm(PyObject *self, PyObject *args) ...@@ -987,6 +992,7 @@ MPZ_powm(PyObject *self, PyObject *args)
Py_DECREF(mpzbase); Py_DECREF(mpzbase);
Py_DECREF(mpzexp); Py_DECREF(mpzexp);
Py_DECREF(mpzmod); Py_DECREF(mpzmod);
Py_DECREF(z);
PyErr_SetString(PyExc_ValueError, "modulus cannot be 0"); PyErr_SetString(PyExc_ValueError, "modulus cannot be 0");
return NULL; return NULL;
} }
......
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