From 253a232d300ac6a508983bbbb6eb6d0235d48722 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Jan 2010 16:44:12 +1300 Subject: [PATCH] pyxattr: Fix memory leaks. --- source4/librpc/ndr/py_xattr.c | 2 +- source4/scripting/python/pyxattr_native.c | 12 ++++++++---- source4/scripting/python/pyxattr_tdb.c | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/source4/librpc/ndr/py_xattr.c b/source4/librpc/ndr/py_xattr.c index 9cf87e24a99..19c5f266728 100644 --- a/source4/librpc/ndr/py_xattr.c +++ b/source4/librpc/ndr/py_xattr.c @@ -78,7 +78,7 @@ static PyObject *py_ntacl_print(PyObject *self, PyObject *args) pr->print = ntacl_print_debug_helper; ndr_print_xattr_NTACL(pr, "file", ntacl); - talloc_free(pr); + talloc_free(mem_ctx); Py_RETURN_NONE; } diff --git a/source4/scripting/python/pyxattr_native.c b/source4/scripting/python/pyxattr_native.c index 70fdf571f1f..9b60039a385 100644 --- a/source4/scripting/python/pyxattr_native.c +++ b/source4/scripting/python/pyxattr_native.c @@ -35,6 +35,7 @@ static PyObject *py_is_xattr_supported(PyObject *self) return Py_True; #endif } + static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args) { char *filename, *attribute; @@ -42,11 +43,12 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args) int blobsize; DATA_BLOB blob; - if (!PyArg_ParseTuple(args, "sss#", &filename,&attribute,&blob.data,&blobsize)) + if (!PyArg_ParseTuple(args, "sss#", &filename, &attribute, &blob.data, + &blobsize)) return NULL; blob.length = blobsize; - ret = wrap_setxattr(filename,attribute,blob.data,blob.length,0); + ret = wrap_setxattr(filename, attribute, blob.data, blob.length, 0); if( ret < 0 ) { if (errno == ENOTSUP) { PyErr_SetFromErrno(PyExc_IOError); @@ -65,7 +67,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args) TALLOC_CTX *mem_ctx; char *buf; PyObject *ret; - if (!PyArg_ParseTuple(args, "ss", &filename,&attribute)) + if (!PyArg_ParseTuple(args, "ss", &filename, &attribute)) return NULL; mem_ctx = talloc_new(NULL); len = wrap_getxattr(filename,attribute,NULL,0); @@ -75,6 +77,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args) } else { PyErr_SetFromErrno(PyExc_TypeError); } + talloc_free(mem_ctx); return NULL; } /* check length ... */ @@ -86,10 +89,11 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args) } else { PyErr_SetFromErrno(PyExc_TypeError); } + talloc_free(mem_ctx); return NULL; } ret = PyString_FromStringAndSize(buf, len); - talloc_free(buf); + talloc_free(mem_ctx); return ret; } diff --git a/source4/scripting/python/pyxattr_tdb.c b/source4/scripting/python/pyxattr_tdb.c index ed5a97fe3cb..f90cfd5a266 100644 --- a/source4/scripting/python/pyxattr_tdb.c +++ b/source4/scripting/python/pyxattr_tdb.c @@ -49,7 +49,8 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args) TALLOC_CTX *mem_ctx; struct tdb_wrap *eadb; - if (!PyArg_ParseTuple(args, "ssss#", &tdbname,&filename,&attribute,&blob.data,&blobsize)) + if (!PyArg_ParseTuple(args, "ssss#", &tdbname, &filename, &attribute, + &blob.data, &blobsize)) return NULL; blob.length = blobsize; @@ -59,13 +60,16 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args) if (eadb == NULL) { PyErr_SetFromErrno(PyExc_IOError); + talloc_free(mem_ctx); return NULL; } status = push_xattr_blob_tdb_raw(eadb,mem_ctx,attribute,filename,-1,&blob); - if( !NT_STATUS_IS_OK(status) ) { - PyErr_SetFromErrno(PyExc_TypeError); + if (!NT_STATUS_IS_OK(status)) { + PyErr_FromNTSTATUS(status); + talloc_free(mem_ctx); return NULL; } + talloc_free(mem_ctx); Py_RETURN_NONE; } @@ -86,14 +90,18 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args) TDB_DEFAULT, O_RDWR|O_CREAT, 0600); if (eadb == NULL) { PyErr_SetFromErrno(PyExc_IOError); + talloc_free(mem_ctx); return NULL; } - status = pull_xattr_blob_tdb_raw(eadb,mem_ctx,attribute,filename,-1,100,&blob); + status = pull_xattr_blob_tdb_raw(eadb, mem_ctx, attribute, filename, + -1, 100, &blob); if (!NT_STATUS_IS_OK(status) || blob.length < 0) { PyErr_FromNTSTATUS(status); + talloc_free(mem_ctx); return NULL; } ret = PyString_FromStringAndSize((char *)blob.data, blob.length); + talloc_free(mem_ctx); return ret; } -- 2.34.1