diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2010-01-21 16:44:12 +1300 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2010-01-21 16:44:12 +1300 |
commit | 253a232d300ac6a508983bbbb6eb6d0235d48722 (patch) | |
tree | b41ed757b251f682c220bc38298f1cecec27a524 /source4/scripting/python | |
parent | 9a253808383e1a2777c3c05a25be88ed25c51a13 (diff) | |
download | samba-253a232d300ac6a508983bbbb6eb6d0235d48722.tar.gz samba-253a232d300ac6a508983bbbb6eb6d0235d48722.tar.bz2 samba-253a232d300ac6a508983bbbb6eb6d0235d48722.zip |
pyxattr: Fix memory leaks.
Diffstat (limited to 'source4/scripting/python')
-rw-r--r-- | source4/scripting/python/pyxattr_native.c | 12 | ||||
-rw-r--r-- | source4/scripting/python/pyxattr_tdb.c | 16 |
2 files changed, 20 insertions, 8 deletions
diff --git a/source4/scripting/python/pyxattr_native.c b/source4/scripting/python/pyxattr_native.c index 70fdf571f1..9b60039a38 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 ed5a97fe3c..f90cfd5a26 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; } |