diff options
| author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-07-11 03:28:17 +0000 | 
|---|---|---|
| committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-07-11 03:28:17 +0000 | 
| commit | 4904829dbf7d8867a5d8c89eeec2969a45448fd8 (patch) | |
| tree | 4970c6e25112ae9e302e0a0e01970e3bffceb079 | |
| parent | dc0c031ad8018bce613b21405fcb58b0bdda60dc (diff) | |
| download | cpython-git-4904829dbf7d8867a5d8c89eeec2969a45448fd8.tar.gz | |
fix two refcount bugs in new string_join implementation:
1. PySequence_Fast_GET_ITEM is a macro and borrows a reference
2. The seq returned from PySequence_Fast must be decref'd
| -rw-r--r-- | Objects/stringobject.c | 8 | 
1 files changed, 2 insertions, 6 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index fd0a570c5f..2667fa9e70 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -774,22 +774,17 @@ string_join(PyStringObject *self, PyObject *args)  		if (!PyString_Check(item)){  			if (PyUnicode_Check(item)) {  				Py_DECREF(res); -				Py_DECREF(item);  				return PyUnicode_Join((PyObject *)self,   						      seq);  			}  			PyErr_Format(PyExc_TypeError,  			     "sequence item %i: expected string, %.80s found",  				     i, item->ob_type->tp_name); -			Py_DECREF(item); -			Py_DECREF(seq);  			goto finally;  		}  		slen = PyString_GET_SIZE(item);  		while (reslen + slen + seplen >= sz) {  			if (_PyString_Resize(&res, sz*2)) { -				Py_DECREF(item); -				Py_DECREF(seq);  				goto finally;  			}  			sz *= 2; @@ -801,15 +796,16 @@ string_join(PyStringObject *self, PyObject *args)  			reslen += seplen;  		}  		memcpy(p, PyString_AS_STRING(item), slen); -		Py_DECREF(item);  		p += slen;  		reslen += slen;  	}  	if (_PyString_Resize(&res, reslen))  		goto finally; +	Py_DECREF(seq);  	return res;    finally: +	Py_DECREF(seq);  	Py_DECREF(res);  	return NULL;  }  | 
