[Python-checkins] CVS: python/dist/src/Objects stringobject.c,2.55,2.56
Barry A. Warsaw
bwarsaw@cnri.reston.va.us
Mon, 6 Mar 2000 09:52:21 -0500 (EST)
Update of /projects/cvsroot/python/dist/src/Objects
In directory anthem:/home/bwarsaw/projects/python/Objects
Modified Files:
stringobject.c
Log Message:
string_join(): Fix memory leaks discovered by Charles Waldman (and a
few other paths through the function that leaked).
Index: stringobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.55
retrieving revision 2.56
diff -C2 -r2.55 -r2.56
*** stringobject.c 2000/02/29 13:59:28 2.55
--- stringobject.c 2000/03/06 14:52:18 2.56
***************
*** 710,715 ****
slen = PyString_GET_SIZE(sitem);
while (reslen + slen + seplen >= sz) {
! if (_PyString_Resize(&res, sz*2))
goto finally;
sz *= 2;
p = PyString_AsString(res) + reslen;
--- 710,717 ----
slen = PyString_GET_SIZE(sitem);
while (reslen + slen + seplen >= sz) {
! if (_PyString_Resize(&res, sz*2)) {
! Py_DECREF(sitem);
goto finally;
+ }
sz *= 2;
p = PyString_AsString(res) + reslen;
***************
*** 721,724 ****
--- 723,727 ----
}
memcpy(p, PyString_AS_STRING(sitem), slen);
+ Py_DECREF(sitem);
p += slen;
reslen += slen;
***************
*** 729,740 ****
PyObject *item = PySequence_GetItem(seq, i);
PyObject *sitem;
! if (!item || !(sitem = PyObject_Str(item))) {
! Py_XDECREF(item);
goto finally;
! }
slen = PyString_GET_SIZE(sitem);
while (reslen + slen + seplen >= sz) {
! if (_PyString_Resize(&res, sz*2))
goto finally;
sz *= 2;
p = PyString_AsString(res) + reslen;
--- 732,749 ----
PyObject *item = PySequence_GetItem(seq, i);
PyObject *sitem;
!
! 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)) {
! Py_DECREF(sitem);
goto finally;
+ }
sz *= 2;
p = PyString_AsString(res) + reslen;
***************
*** 746,749 ****
--- 755,759 ----
}
memcpy(p, PyString_AS_STRING(sitem), slen);
+ Py_DECREF(sitem);
p += slen;
reslen += slen;