[Python-checkins] cpython: Fix ref leak in error case of unicode rindex and rfind

christian.heimes python-checkins at python.org
Sat Jun 29 21:17:43 CEST 2013


http://hg.python.org/cpython/rev/d0fb17896c95
changeset:   84378:d0fb17896c95
user:        Christian Heimes <christian at cheimes.de>
date:        Sat Jun 29 21:17:34 2013 +0200
summary:
  Fix ref leak in error case of unicode rindex and rfind
CID 983320: Resource leak (RESOURCE_LEAK)
CID 983321: Resource leak (RESOURCE_LEAK)
leaked_storage: Variable substring going out of scope leaks the storage it points to.

files:
  Objects/unicodeobject.c |  24 ++++++++++++++++--------
  1 files changed, 16 insertions(+), 8 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -12248,10 +12248,14 @@
                                             &start, &end))
         return NULL;
 
-    if (PyUnicode_READY(self) == -1)
-        return NULL;
-    if (PyUnicode_READY(substring) == -1)
-        return NULL;
+    if (PyUnicode_READY(self) == -1) {
+        Py_DECREF(substring);
+        return NULL;
+    }
+    if (PyUnicode_READY(substring) == -1) {
+        Py_DECREF(substring);
+        return NULL;
+    }
 
     result = any_find_slice(-1, self, substring, start, end);
 
@@ -12280,10 +12284,14 @@
                                             &start, &end))
         return NULL;
 
-    if (PyUnicode_READY(self) == -1)
-        return NULL;
-    if (PyUnicode_READY(substring) == -1)
-        return NULL;
+    if (PyUnicode_READY(self) == -1) {
+        Py_DECREF(substring);
+        return NULL;
+    }
+    if (PyUnicode_READY(substring) == -1) {
+        Py_DECREF(substring);
+        return NULL;
+    }
 
     result = any_find_slice(-1, self, substring, start, end);
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list