diff options
author | Noel Power <noel.power@suse.com> | 2018-11-09 16:47:00 +0000 |
---|---|---|
committer | Douglas Bagnall <dbagnall@samba.org> | 2019-01-13 00:40:26 +0100 |
commit | 5232979de8394944dccae848207aae65c1a65ec1 (patch) | |
tree | 118c7361b0f57149d83773658f4a9d0b22fc87f5 /python | |
parent | e61f9406de17a037106ce5f81feb85a8b477a986 (diff) | |
download | samba-5232979de8394944dccae848207aae65c1a65ec1.tar.gz |
python: Fix memory leak with ParseTuple (using 'es' format)
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'python')
-rw-r--r-- | python/pyglue.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/python/pyglue.c b/python/pyglue.c index 22ac53f3c66..e4f961fdaf7 100644 --- a/python/pyglue.c +++ b/python/pyglue.c @@ -300,28 +300,36 @@ static PyObject *py_strcasecmp_m(PyObject *self, PyObject *args) { const char *s1 = NULL; const char *s2 = NULL; - + long cmp_result = 0; if (!PyArg_ParseTuple(args, "eses", "utf8", &s1, "utf8", &s2)) { return NULL; } - return PyInt_FromLong(strcasecmp_m(s1, s2)); + cmp_result = strcasecmp_m(s1, s2); + PyMem_Free(discard_const_p(char, s1)); + PyMem_Free(discard_const_p(char, s2)); + return PyInt_FromLong(cmp_result); } static PyObject *py_strstr_m(PyObject *self, PyObject *args) { const char *s1 = NULL; const char *s2 = NULL; - char *ret = NULL; - + char *strstr_ret = NULL; + PyObject *result = NULL; if (!PyArg_ParseTuple(args, "eses", "utf8", &s1, "utf8", &s2)) return NULL; - ret = strstr_m(s1, s2); - if (!ret) { + strstr_ret = strstr_m(s1, s2); + if (!strstr_ret) { + PyMem_Free(discard_const_p(char, s1)); + PyMem_Free(discard_const_p(char, s2)); Py_RETURN_NONE; } - return PyUnicode_FromString(ret); + result = PyUnicode_FromString(strstr_ret); + PyMem_Free(discard_const_p(char, s1)); + PyMem_Free(discard_const_p(char, s2)); + return result; } static PyMethodDef py_misc_methods[] = { |