summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2000-03-06 14:52:18 (GMT)
committerBarry Warsaw <barry@python.org>2000-03-06 14:52:18 (GMT)
commitbf3258308412de3402ab02cf193297ba88442fed (patch)
treefdbdfc55d20414b9dfe854b4771b14a6cddb51b1 /Objects/stringobject.c
parent7f3cfd50fade7da7cda9a2168b22b8ce4defce28 (diff)
downloadcpython-bf3258308412de3402ab02cf193297ba88442fed.zip
cpython-bf3258308412de3402ab02cf193297ba88442fed.tar.gz
cpython-bf3258308412de3402ab02cf193297ba88442fed.tar.bz2
string_join(): Fix memory leaks discovered by Charles Waldman (and a
few other paths through the function that leaked).
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index ec49dd7..bc1bb41 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -709,8 +709,10 @@ string_join(self, args)
goto finally;
slen = PyString_GET_SIZE(sitem);
while (reslen + slen + seplen >= sz) {
- if (_PyString_Resize(&res, sz*2))
+ if (_PyString_Resize(&res, sz*2)) {
+ Py_DECREF(sitem);
goto finally;
+ }
sz *= 2;
p = PyString_AsString(res) + reslen;
}
@@ -720,6 +722,7 @@ string_join(self, args)
reslen += seplen;
}
memcpy(p, PyString_AS_STRING(sitem), slen);
+ Py_DECREF(sitem);
p += slen;
reslen += slen;
}
@@ -728,14 +731,20 @@ string_join(self, args)
for (i = 0; i < seqlen; i++) {
PyObject *item = PySequence_GetItem(seq, i);
PyObject *sitem;
- if (!item || !(sitem = PyObject_Str(item))) {
- Py_XDECREF(item);
+
+ if (!item)
goto finally;
- }
+ sitem = PyObject_Str(item);
+ Py_DECREF(item);
+ if (!sitem)
+ goto finally;
+
slen = PyString_GET_SIZE(sitem);
while (reslen + slen + seplen >= sz) {
- if (_PyString_Resize(&res, sz*2))
+ if (_PyString_Resize(&res, sz*2)) {
+ Py_DECREF(sitem);
goto finally;
+ }
sz *= 2;
p = PyString_AsString(res) + reslen;
}
@@ -745,6 +754,7 @@ string_join(self, args)
reslen += seplen;
}
memcpy(p, PyString_AS_STRING(sitem), slen);
+ Py_DECREF(sitem);
p += slen;
reslen += slen;
}