summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-06-26 23:22:57 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-06-26 23:22:57 (GMT)
commita006c37472ccca46edf6b138a386ff100c621a80 (patch)
tree482294199ae9200632e92391489f7b631fe8d9a2 /Objects
parent555a96475d81eb1d38eeb930578aa35dab857a46 (diff)
downloadcpython-a006c37472ccca46edf6b138a386ff100c621a80.zip
cpython-a006c37472ccca46edf6b138a386ff100c621a80.tar.gz
cpython-a006c37472ccca46edf6b138a386ff100c621a80.tar.bz2
SF bug #980419: int left-shift causes memory leak
Diffstat (limited to 'Objects')
-rw-r--r--Objects/intobject.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 25a01c2..bdf7da3 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -751,6 +751,8 @@ static PyObject *
int_lshift(PyIntObject *v, PyIntObject *w)
{
long a, b, c;
+ PyObject *vv, *ww, *result;
+
CONVERT_TO_LONG(v, a);
CONVERT_TO_LONG(w, b);
if (b < 0) {
@@ -760,13 +762,33 @@ int_lshift(PyIntObject *v, PyIntObject *w)
if (a == 0 || b == 0)
return int_pos(v);
if (b >= LONG_BIT) {
- return PyNumber_Lshift(PyLong_FromLong(PyInt_AS_LONG(v)),
- PyLong_FromLong(PyInt_AS_LONG(w)));
+ vv = PyLong_FromLong(PyInt_AS_LONG(v));
+ if (vv == NULL)
+ return NULL;
+ ww = PyLong_FromLong(PyInt_AS_LONG(w));
+ if (ww == NULL) {
+ Py_DECREF(vv);
+ return NULL;
+ }
+ result = PyNumber_Lshift(vv, ww);
+ Py_DECREF(vv);
+ Py_DECREF(ww);
+ return result;
}
c = a << b;
if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
- return PyNumber_Lshift(PyLong_FromLong(PyInt_AS_LONG(v)),
- PyLong_FromLong(PyInt_AS_LONG(w)));
+ vv = PyLong_FromLong(PyInt_AS_LONG(v));
+ if (vv == NULL)
+ return NULL;
+ ww = PyLong_FromLong(PyInt_AS_LONG(w));
+ if (ww == NULL) {
+ Py_DECREF(vv);
+ return NULL;
+ }
+ result = PyNumber_Lshift(vv, ww);
+ Py_DECREF(vv);
+ Py_DECREF(ww);
+ return result;
}
return PyInt_FromLong(c);
}