From b529f3805388ce553e05975f9cc090bfb10c505e Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sun, 11 Nov 2012 23:49:48 +0100 Subject: Fix leaks in _fastmath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix leaks in getRandomInteger and rsaKeyNew. If randfunc throws an exception they both don't clean up properly. Thanks to Andreas Stührk for helping me to debug these two leaks. --- src/_fastmath.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/_fastmath.c') diff --git a/src/_fastmath.c b/src/_fastmath.c index 1317765..99b1c43 100644 --- a/src/_fastmath.c +++ b/src/_fastmath.c @@ -746,6 +746,7 @@ rsaKey_new (PyObject * self, PyObject * args) } else { if (factorize_N_from_D(key)) { + Py_DECREF(key); PyErr_SetString(PyExc_ValueError, "Unable to compute factors p and q from exponent d."); return NULL; @@ -1176,7 +1177,7 @@ getRNG (void) static int getRandomInteger (mpz_t n, unsigned long bits, PyObject *randfunc_) { - PyObject *arglist, *randfunc=NULL, *rng=NULL, *rand_bytes=NULL; + PyObject *arglist=NULL, *randfunc=NULL, *rng=NULL, *rand_bytes=NULL; int return_val = 1; unsigned long bytes = bits / 8; unsigned long odd_bits = bits % 8; @@ -1216,7 +1217,6 @@ getRandomInteger (mpz_t n, unsigned long bits, PyObject *randfunc_) return_val = 0; goto cleanup; } - Py_DECREF (arglist); if (!PyBytes_Check (rand_bytes)) { PyErr_SetString (PyExc_TypeError, @@ -1230,6 +1230,7 @@ getRandomInteger (mpz_t n, unsigned long bits, PyObject *randfunc_) mpz_fdiv_q_2exp (n, n, 8 - odd_bits); cleanup: + Py_XDECREF (arglist); Py_XDECREF (rand_bytes); if (rng) { -- cgit v1.2.1