[Python-checkins] r76320 - in python/branches/release31-maint: Objects/rangeobject.c

benjamin.peterson python-checkins at python.org
Mon Nov 16 01:36:18 CET 2009


Author: benjamin.peterson
Date: Mon Nov 16 01:36:18 2009
New Revision: 76320

Log:
Merged revisions 76319 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r76319 | benjamin.peterson | 2009-11-15 18:34:25 -0600 (Sun, 15 Nov 2009) | 4 lines
  
  fix one visible and several possible refleaks in rangeobject.c
  
  In some cases, the code was just reordered to allow for less decrefing.
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Objects/rangeobject.c

Modified: python/branches/release31-maint/Objects/rangeobject.c
==============================================================================
--- python/branches/release31-maint/Objects/rangeobject.c	(original)
+++ python/branches/release31-maint/Objects/rangeobject.c	Mon Nov 16 01:36:18 2009
@@ -476,6 +476,7 @@
     it->step = step;
     ulen = get_len_of_range(start, stop, step);
     if (ulen > (unsigned long)LONG_MAX) {
+        Py_DECREF(it);
         PyErr_SetString(PyExc_OverflowError,
                         "range too large to represent as a range_iterator");
         return NULL;
@@ -527,16 +528,14 @@
     if (!one)
         return NULL;
 
-    product = PyNumber_Multiply(r->index, r->step);
-    if (!product) {
-        Py_DECREF(one);
-        return NULL;
-    }
-
     new_index = PyNumber_Add(r->index, one);
     Py_DECREF(one);
-    if (!new_index) {
-        Py_DECREF(product);
+    if (!new_index)
+        return NULL;
+
+    product = PyNumber_Multiply(r->index, r->step);
+    if (!product) {
+        Py_DECREF(new_index);
         return NULL;
     }
 
@@ -546,6 +545,9 @@
         Py_DECREF(r->index);
         r->index = new_index;
     }
+    else {
+        Py_DECREF(new_index);
+    }
 
     return result;
 }
@@ -724,6 +726,9 @@
     if (!len)
         goto create_failure;
 
+    /* Steal reference to len. */
+    it->len = len;
+
     one = PyLong_FromLong(1);
     if (!one)
         goto create_failure;
@@ -745,24 +750,16 @@
         goto create_failure;
 
     it->step = PyNumber_Negative(range->step);
-    if (!it->step) {
-        Py_DECREF(it->start);
+    if (!it->step)
         goto create_failure;
-    }
-
-    /* Steal reference to len. */
-    it->len = len;
 
     it->index = PyLong_FromLong(0);
-    if (!it->index) {
-        Py_DECREF(it);
-        return NULL;
-    }
+    if (!it->index)
+        goto create_failure;
 
     return (PyObject *)it;
 
 create_failure:
-    Py_XDECREF(len);
-    PyObject_Del(it);
+    Py_DECREF(it);
     return NULL;
 }


More information about the Python-checkins mailing list