summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2011-10-01 14:35:40 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2011-10-01 14:35:40 (GMT)
commit0b1d3489906e0047808ee4468fb9681a3e1a8485 (patch)
treedfd3b146e6e9d354c7bf5eb98f6da7d904ee3e9a
parent5c0fb00ad80d6c70a9a51f3e3d2c1bfcecbd0840 (diff)
downloadcpython-0b1d3489906e0047808ee4468fb9681a3e1a8485.zip
cpython-0b1d3489906e0047808ee4468fb9681a3e1a8485.tar.gz
cpython-0b1d3489906e0047808ee4468fb9681a3e1a8485.tar.bz2
Issue 13085: Fix some memory leaks. Patch by Stefan Krah.
-rw-r--r--Objects/unicodeobject.c1
-rw-r--r--Python/import.c30
2 files changed, 20 insertions, 11 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 51cd855..06e7a91 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9075,6 +9075,7 @@ replace(PyObject *self, PyObject *str1,
PyUnicode_KIND_SIZE(rkind, slen-i));
}
u = PyUnicode_FromKindAndData(rkind, res, new_size);
+ PyMem_Free(res);
}
if (srelease)
PyMem_FREE(sbuf);
diff --git a/Python/import.c b/Python/import.c
index 9f38061..901b733 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1564,8 +1564,10 @@ get_sourcefile(PyObject *filename)
if (py == NULL)
goto error;
- if (_Py_stat(py, &statbuf) == 0 && S_ISREG(statbuf.st_mode))
+ if (_Py_stat(py, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
+ PyMem_Free(fileuni);
return py;
+ }
Py_DECREF(py);
goto unchanged;
@@ -3074,7 +3076,7 @@ load_next(PyObject *mod, PyObject *altmod,
Py_ssize_t len;
Py_UCS4 *p;
PyObject *fullname, *name, *result, *mark_name;
- const Py_UCS4 *nameuni;
+ Py_UCS4 *nameuni;
*p_outputname = NULL;
@@ -3095,7 +3097,7 @@ load_next(PyObject *mod, PyObject *altmod,
if (len == 0) {
PyErr_SetString(PyExc_ValueError,
"Empty module name");
- return NULL;
+ goto error;
}
}
else
@@ -3104,7 +3106,7 @@ load_next(PyObject *mod, PyObject *altmod,
if (*p_buflen+len+1 >= bufsize) {
PyErr_SetString(PyExc_ValueError,
"Module name too long");
- return NULL;
+ goto error;
}
p = buf + *p_buflen;
@@ -3119,12 +3121,12 @@ load_next(PyObject *mod, PyObject *altmod,
fullname = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,
buf, *p_buflen);
if (fullname == NULL)
- return NULL;
+ goto error;
name = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,
p, len);
if (name == NULL) {
Py_DECREF(fullname);
- return NULL;
+ goto error;
}
result = import_submodule(mod, name, fullname);
Py_DECREF(fullname);
@@ -3138,12 +3140,12 @@ load_next(PyObject *mod, PyObject *altmod,
buf, *p_buflen);
if (mark_name == NULL) {
Py_DECREF(result);
- return NULL;
+ goto error;
}
if (mark_miss(mark_name) != 0) {
Py_DECREF(result);
Py_DECREF(mark_name);
- return NULL;
+ goto error;
}
Py_DECREF(mark_name);
Py_UCS4_strncpy(buf, nameuni, len);
@@ -3154,13 +3156,13 @@ load_next(PyObject *mod, PyObject *altmod,
else
Py_DECREF(name);
if (result == NULL)
- return NULL;
+ goto error;
if (result == Py_None) {
Py_DECREF(result);
PyErr_Format(PyExc_ImportError,
"No module named %R", inputname);
- return NULL;
+ goto error;
}
if (dot != NULL) {
@@ -3168,11 +3170,17 @@ load_next(PyObject *mod, PyObject *altmod,
dot+1, Py_UCS4_strlen(dot+1));
if (*p_outputname == NULL) {
Py_DECREF(result);
- return NULL;
+ goto error;
}
}
+out:
+ PyMem_Free(nameuni);
return result;
+
+error:
+ PyMem_Free(nameuni);
+ return NULL;
}
static int