[Python-checkins] r68419 - in sandbox/trunk/io-c: _bufferedio.c _iobase.c _textio.c
amaury.forgeotdarc
python-checkins at python.org
Fri Jan 9 01:21:30 CET 2009
Author: amaury.forgeotdarc
Date: Fri Jan 9 01:21:30 2009
New Revision: 68419
Log:
Kill more reference leaks
Modified:
sandbox/trunk/io-c/_bufferedio.c
sandbox/trunk/io-c/_iobase.c
sandbox/trunk/io-c/_textio.c
Modified: sandbox/trunk/io-c/_bufferedio.c
==============================================================================
--- sandbox/trunk/io-c/_bufferedio.c (original)
+++ sandbox/trunk/io-c/_bufferedio.c Fri Jan 9 01:21:30 2009
@@ -882,14 +882,14 @@
static PyObject *
_BufferedReader_read_unlocked(BufferedObject *self, Py_ssize_t n)
{
- PyObject *data, *chunks, *res = NULL;
+ PyObject *data, *res = NULL;
Py_ssize_t current_size, remaining, written;
char *out;
static PyObject *sep = NULL;
/* Special case for when the number of bytes to read is unspecified. */
if (n == -1) {
- chunks = PyList_New(0);
+ PyObject *chunks = PyList_New(0);
if (chunks == NULL)
return NULL;
@@ -908,8 +908,10 @@
/* We're going past the buffer's bounds, flush it */
if (self->writable) {
res = _BufferedWriter_flush_unlocked(self, 1);
- if (res == NULL)
+ if (res == NULL) {
+ Py_DECREF(chunks);
return NULL;
+ }
Py_CLEAR(res);
}
while (1) {
@@ -949,6 +951,7 @@
}
}
res =_PyBytes_Join(sep, chunks);
+ Py_DECREF(data);
Py_DECREF(chunks);
return res;
}
@@ -1533,7 +1536,7 @@
return -1;
}
self->reader = (BufferedObject *)PyType_GenericNew(
- &PyBufferedReader_Type, args, NULL);
+ &PyBufferedReader_Type, args, NULL);
Py_DECREF(args);
if (self->reader == NULL)
return -1;
@@ -1544,7 +1547,7 @@
return -1;
}
self->writer = (BufferedObject *)PyType_GenericNew(
- &PyBufferedWriter_Type, args, NULL);
+ &PyBufferedWriter_Type, args, NULL);
Py_DECREF(args);
if (self->writer == NULL) {
Py_CLEAR(self->reader);
Modified: sandbox/trunk/io-c/_iobase.c
==============================================================================
--- sandbox/trunk/io-c/_iobase.c (original)
+++ sandbox/trunk/io-c/_iobase.c Fri Jan 9 01:21:30 2009
@@ -391,8 +391,10 @@
if (b == NULL)
goto fail;
assert(PyBytes_Check(b));
- if (Py_SIZE(b) == 0)
+ if (Py_SIZE(b) == 0) {
+ Py_DECREF(b);
break;
+ }
old_size = Py_SIZE(buffer);
PyByteArray_Resize(buffer, old_size + Py_SIZE(b));
@@ -452,7 +454,7 @@
IOBase_readlines(PyObject *self, PyObject *args)
{
Py_ssize_t hint = -1, length = 0;
- PyObject *hintobj = Py_None, *line, *result;
+ PyObject *hintobj = Py_None, *result;
if (!PyArg_ParseTuple(args, "|O:readlines", &hintobj)) {
return NULL;
@@ -478,7 +480,7 @@
}
while (1) {
- line = PyObject_CallMethod(self, "__next__", NULL);
+ PyObject *line = PyIter_Next(self, "__next__");
if (line == NULL) {
if (PyErr_Occurred()) {
Py_DECREF(result);
@@ -487,7 +489,6 @@
else
break; /* SopIteration raised */
}
- assert (PyBytes_Check(line));
if (PyList_Append(result, line) < 0) {
Py_DECREF(line);
Modified: sandbox/trunk/io-c/_textio.c
==============================================================================
--- sandbox/trunk/io-c/_textio.c (original)
+++ sandbox/trunk/io-c/_textio.c Fri Jan 9 01:21:30 2009
@@ -291,12 +291,16 @@
if (state == NULL)
return NULL;
- if (!PyArg_Parse(state, "(OK)", &buffer, &flag))
+ if (!PyArg_Parse(state, "(OK)", &buffer, &flag)) {
+ Py_DECREF(state);
return NULL;
+ }
+ Py_INCREF(buffer);
+ Py_DECREF(state);
flag <<= 1;
if (self->pendingcr)
flag |= 1;
- return Py_BuildValue("OK", buffer, flag);
+ return Py_BuildValue("NK", buffer, flag);
}
static PyObject *
@@ -871,6 +875,7 @@
goto fail;
decoded = PyObject_CallMethod(self->decoder, "decode",
"Oi", bytes, /*final=*/1);
+ Py_DECREF(bytes);
if (decoded == NULL)
goto fail;
@@ -1481,6 +1486,7 @@
Py_DECREF(saved_state);
if (res == NULL)
return NULL;
+ Py_DECREF(res);
/* The returned cookie corresponds to the last safe start point. */
cookie.chars_to_skip = Py_SAFE_DOWNCAST(chars_to_skip, Py_ssize_t, int);
More information about the Python-checkins
mailing list