summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-12-06 20:03:56 (GMT)
committerGuido van Rossum <guido@python.org>2001-12-06 20:03:56 (GMT)
commit604ddf80d891f666c677d23b83c3c9f8125ee2b5 (patch)
treea5386610833f3ec3e72c9fe6358f5d5e20cad680
parenta631f580ea4bb9670263f701f41589ab7d591d6f (diff)
downloadcpython-604ddf80d891f666c677d23b83c3c9f8125ee2b5.zip
cpython-604ddf80d891f666c677d23b83c3c9f8125ee2b5.tar.gz
cpython-604ddf80d891f666c677d23b83c3c9f8125ee2b5.tar.bz2
Fix for #489669 (Neil Norwitz): memory leak in test_descr (unicode).
This is best reproduced by while 1: class U(unicode): pass U(u"xxxxxx") The unicode_dealloc() code wasn't properly freeing the str and defenc fields of the Unicode object when freeing a subtype instance. Fixed this by a subtle refactoring that actually reduces the amount of code slightly.
-rw-r--r--Objects/unicodeobject.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index c456b57..68afaa0 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -226,11 +226,8 @@ PyUnicodeObject *_PyUnicode_New(int length)
static
void unicode_dealloc(register PyUnicodeObject *unicode)
{
- if (!PyUnicode_CheckExact(unicode)) {
- unicode->ob_type->tp_free((PyObject *)unicode);
- return;
- }
- if (unicode_freelist_size < MAX_UNICODE_FREELIST_SIZE) {
+ if (PyUnicode_CheckExact(unicode) &&
+ unicode_freelist_size < MAX_UNICODE_FREELIST_SIZE) {
/* Keep-Alive optimization */
if (unicode->length >= KEEPALIVE_SIZE_LIMIT) {
PyMem_DEL(unicode->str);
@@ -249,7 +246,7 @@ void unicode_dealloc(register PyUnicodeObject *unicode)
else {
PyMem_DEL(unicode->str);
Py_XDECREF(unicode->defenc);
- PyObject_DEL(unicode);
+ unicode->ob_type->tp_free((PyObject *)unicode);
}
}