From 14b6d92e212c5c6113f8c9b8d6a0645381379730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Tue, 6 Feb 2007 21:05:30 +0000 Subject: Fix refcounting bugs related to CONVERT_BINOP. --- Objects/longobject.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/Objects/longobject.c b/Objects/longobject.c index 250215c..834e2c2 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -2147,8 +2147,12 @@ static PyObject * long_richcompare(PyObject *self, PyObject *other, int op) { PyLongObject *a, *b; + PyObject *result; CONVERT_BINOP((PyObject *)self, (PyObject *)other, &a, &b); - return Py_CmpToRich(op, long_compare(a, b)); + result = Py_CmpToRich(op, long_compare(a, b)); + Py_DECREF(a); + Py_DECREF(b); + return result; } static long @@ -2283,9 +2287,13 @@ long_add(PyLongObject *v, PyLongObject *w) CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b); - if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1) - return PyInt_FromLong(MEDIUM_VALUE(a) + - MEDIUM_VALUE(b)); + if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1) { + PyObject *result = PyInt_FromLong(MEDIUM_VALUE(a) + + MEDIUM_VALUE(b)); + Py_DECREF(a); + Py_DECREF(b); + return result; + } if (a->ob_size < 0) { if (b->ob_size < 0) { z = x_add(a, b); @@ -2313,8 +2321,13 @@ long_sub(PyLongObject *v, PyLongObject *w) CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b); - if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1) - return PyLong_FromLong(MEDIUM_VALUE(a)-MEDIUM_VALUE(b)); + if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1) { + PyObject* r; + r = PyLong_FromLong(MEDIUM_VALUE(a)-MEDIUM_VALUE(b)); + Py_DECREF(a); + Py_DECREF(b); + return r; + } if (a->ob_size < 0) { if (b->ob_size < 0) z = x_sub(a, b); @@ -2744,8 +2757,13 @@ long_mul(PyLongObject *v, PyLongObject *w) return Py_NotImplemented; } - if (ABS(v->ob_size) <= 1 && ABS(w->ob_size) <= 1) - return PyLong_FromLong(MEDIUM_VALUE(v)*MEDIUM_VALUE(w)); + if (ABS(v->ob_size) <= 1 && ABS(w->ob_size) <= 1) { + PyObject *r; + r = PyLong_FromLong(MEDIUM_VALUE(v)*MEDIUM_VALUE(w)); + Py_DECREF(a); + Py_DECREF(b); + return r; + } z = k_mul(a, b); /* Negate if exactly one of the inputs is negative. */ -- cgit v0.12