mp.c: Arrange to free `xx' on exit.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 10 Nov 2019 22:41:19 +0000 (22:41 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 22 Nov 2019 22:18:10 +0000 (22:18 +0000)
mp.c

diff --git a/mp.c b/mp.c
index 77f7c3c..fff4aec 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -1721,7 +1721,7 @@ static PyObject *mpcrt_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
   int n, i = 0;
   char *kwlist[] = { "mv", 0 };
   PyObject *q = 0, *x;
-  mp *xx;
+  mp *xx = MP_NEW;
   mpcrt_pyobj *c = 0;
 
   if (PyTuple_Size(arg) > 1)
@@ -1738,11 +1738,12 @@ static PyObject *mpcrt_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
     if ((x = PySequence_GetItem(q, i)) == 0) goto end;
     xx = getmp(x); Py_DECREF(x); if (!xx) goto end;
     if (MP_CMP(xx, <=, MP_ZERO)) VALERR("moduli must be positive");
-    v[i].m = xx; v[i].n = 0; v[i].ni = 0; v[i].nni = 0;
+    v[i].m = xx; v[i].n = 0; v[i].ni = 0; v[i].nni = 0; xx = MP_NEW;
   }
   c = (mpcrt_pyobj *)ty->tp_alloc(ty, 0);
   mpcrt_create(&c->c, v, n, 0);
   Py_DECREF(q);
+  mp_drop(xx);
   return ((PyObject *)c);
 
 end:
@@ -1753,6 +1754,7 @@ end:
     xfree(v);
   }
   Py_XDECREF(q);
+  mp_drop(xx);
   return (0);
 }