[Python-checkins] r69647 - python/branches/io-c/Modules/_fileio.c
antoine.pitrou
python-checkins at python.org
Sun Feb 15 20:20:23 CET 2009
Author: antoine.pitrou
Date: Sun Feb 15 20:20:22 2009
New Revision: 69647
Log:
Fix leak in FileIO constructor
Modified:
python/branches/io-c/Modules/_fileio.c
Modified: python/branches/io-c/Modules/_fileio.c
==============================================================================
--- python/branches/io-c/Modules/_fileio.c (original)
+++ python/branches/io-c/Modules/_fileio.c Sun Feb 15 20:20:22 2009
@@ -178,7 +178,7 @@
PyFileIOObject *self = (PyFileIOObject *) oself;
static char *kwlist[] = {"file", "mode", "closefd", NULL};
const char *name = NULL;
- PyObject *nameobj;
+ PyObject *nameobj, *stringobj = NULL;
char *mode = "r";
char *s;
#ifdef MS_WINDOWS
@@ -233,22 +233,22 @@
return -1;
}
else {
- PyObject *s;
PyObject *u = PyUnicode_FromObject(nameobj);
if (u == NULL)
return -1;
- s = PyUnicode_AsEncodedString(
+ stringobj = PyUnicode_AsEncodedString(
u, Py_FileSystemDefaultEncoding, NULL);
Py_DECREF(u);
- if (s == NULL)
+ if (stringobj == NULL)
return -1;
- if (!PyBytes_Check(s)) {
+ if (!PyBytes_Check(stringobj)) {
PyErr_SetString(PyExc_TypeError,
"encoder failed to return bytes");
+ goto error;
}
- name = PyBytes_AS_STRING(s);
+ name = PyBytes_AS_STRING(stringobj);
}
}
@@ -369,6 +369,7 @@
ret = -1;
done:
+ Py_CLEAR(stringobj);
return ret;
}
More information about the Python-checkins
mailing list