[Python-checkins] cpython: fix possible refleaks if PyUnicode_READY fails

benjamin.peterson python-checkins at python.org
Sat Jan 14 19:37:37 CET 2012


http://hg.python.org/cpython/rev/9cd5e8ee1d02
changeset: 74407:9cd5e8ee1d02
user: Benjamin Peterson <benjamin at python.org>
date: Sat Jan 14 13:37:31 2012 -0500
summary:
 fix possible refleaks if PyUnicode_READY fails
files:
 Objects/unicodeobject.c | 18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -2488,8 +2488,12 @@
 PyObject *str;
 assert(obj);
 str = PyObject_Str(obj);
- if (!str || PyUnicode_READY(str) == -1)
+ if (!str)
 goto fail;
+ if (PyUnicode_READY(str) == -1) {
+ Py_DECREF(str);
+ goto fail;
+ }
 argmaxchar = PyUnicode_MAX_CHAR_VALUE(str);
 maxchar = Py_MAX(maxchar, argmaxchar);
 n += PyUnicode_GET_LENGTH(str);
@@ -2503,8 +2507,12 @@
 PyObject *repr;
 assert(obj);
 repr = PyObject_Repr(obj);
- if (!repr || PyUnicode_READY(repr) == -1)
+ if (!repr)
 goto fail;
+ if (PyUnicode_READY(repr) == -1) {
+ Py_DECREF(repr);
+ goto fail;
+ }
 argmaxchar = PyUnicode_MAX_CHAR_VALUE(repr);
 maxchar = Py_MAX(maxchar, argmaxchar);
 n += PyUnicode_GET_LENGTH(repr);
@@ -2518,8 +2526,12 @@
 PyObject *ascii;
 assert(obj);
 ascii = PyObject_ASCII(obj);
- if (!ascii || PyUnicode_READY(ascii) == -1)
+ if (!ascii)
 goto fail;
+ if (PyUnicode_READY(ascii) == -1) {
+ Py_DECREF(ascii);
+ goto fail;
+ }
 argmaxchar = PyUnicode_MAX_CHAR_VALUE(ascii);
 maxchar = Py_MAX(maxchar, argmaxchar);
 n += PyUnicode_GET_LENGTH(ascii);
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

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