]> granicus.if.org Git - python/commitdiff
Fix ref leak in error case of unicode rindex and rfind
authorChristian Heimes <christian@cheimes.de>
Sat, 29 Jun 2013 19:17:34 +0000 (21:17 +0200)
committerChristian Heimes <christian@cheimes.de>
Sat, 29 Jun 2013 19:17:34 +0000 (21:17 +0200)
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.

Objects/unicodeobject.c

index 30a925c3413664113ab8dd9b3555450c0aabe741..fe0337fc46e8b83081c5309efbb4cec91b552901 100644 (file)
@@ -12248,10 +12248,14 @@ unicode_rfind(PyObject *self, PyObject *args)
                                             &start, &end))
         return NULL;
 
-    if (PyUnicode_READY(self) == -1)
+    if (PyUnicode_READY(self) == -1) {
+        Py_DECREF(substring);
         return NULL;
-    if (PyUnicode_READY(substring) == -1)
+    }
+    if (PyUnicode_READY(substring) == -1) {
+        Py_DECREF(substring);
         return NULL;
+    }
 
     result = any_find_slice(-1, self, substring, start, end);
 
@@ -12280,10 +12284,14 @@ unicode_rindex(PyObject *self, PyObject *args)
                                             &start, &end))
         return NULL;
 
-    if (PyUnicode_READY(self) == -1)
+    if (PyUnicode_READY(self) == -1) {
+        Py_DECREF(substring);
         return NULL;
-    if (PyUnicode_READY(substring) == -1)
+    }
+    if (PyUnicode_READY(substring) == -1) {
+        Py_DECREF(substring);
         return NULL;
+    }
 
     result = any_find_slice(-1, self, substring, start, end);