[Python-checkins] cpython: Fix ref leak in error case of unicode find, count, formatlong

christian.heimes python-checkins at python.org
Sat Jun 29 21:33:49 CEST 2013


http://hg.python.org/cpython/rev/cad335e0b205
changeset: 84380:cad335e0b205
user: Christian Heimes <christian at cheimes.de>
date: Sat Jun 29 21:33:36 2013 +0200
summary:
 Fix ref leak in error case of unicode find, count, formatlong
CID 983315: Resource leak (RESOURCE_LEAK)
CID 983316: Resource leak (RESOURCE_LEAK)
CID 983317: Resource leak (RESOURCE_LEAK)
files:
 Objects/unicodeobject.c | 18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -10875,8 +10875,10 @@
 
 kind1 = PyUnicode_KIND(self);
 kind2 = PyUnicode_KIND(substring);
- if (kind2 > kind1)
+ if (kind2 > kind1) {
+ Py_DECREF(substring);
 return PyLong_FromLong(0);
+ }
 kind = kind1;
 buf1 = PyUnicode_DATA(self);
 buf2 = PyUnicode_DATA(substring);
@@ -11054,10 +11056,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);
 
@@ -13581,12 +13587,14 @@
 
 /* To modify the string in-place, there can only be one reference. */
 if (Py_REFCNT(result) != 1) {
+ Py_DECREF(result);
 PyErr_BadInternalCall();
 return NULL;
 }
 buf = PyUnicode_DATA(result);
 llen = PyUnicode_GET_LENGTH(result);
 if (llen > INT_MAX) {
+ Py_DECREF(result);
 PyErr_SetString(PyExc_ValueError,
 "string too large in _PyBytes_FormatLong");
 return NULL;
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /