diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-01-14 18:37:31 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-01-14 18:37:31 (GMT) |
commit | c8d8b8861e2cadec76c534e996cbf6330a6e81de (patch) | |
tree | ae4394a325acf02792eb997f1becd15e834c9060 | |
parent | bac79498c814dac877a665a4c82ad9084fbc0779 (diff) | |
download | cpython-c8d8b8861e2cadec76c534e996cbf6330a6e81de.zip cpython-c8d8b8861e2cadec76c534e996cbf6330a6e81de.tar.gz cpython-c8d8b8861e2cadec76c534e996cbf6330a6e81de.tar.bz2 |
fix possible refleaks if PyUnicode_READY fails
-rw-r--r-- | Objects/unicodeobject.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 40c1bd8..e97ce1f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -2488,8 +2488,12 @@ PyUnicode_FromFormatV(const char *format, va_list vargs) 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 @@ PyUnicode_FromFormatV(const char *format, va_list vargs) 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 @@ PyUnicode_FromFormatV(const char *format, va_list vargs) 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); |