diff options
author | Matthias Dieter Wallnöfer <mdw@samba.org> | 2010-06-18 22:08:58 +0200 |
---|---|---|
committer | Matthias Dieter Wallnöfer <mdw@samba.org> | 2010-06-19 17:53:21 +0200 |
commit | ca34ffaaac4cc98dc600cb8b5bc6e8ecf93f7492 (patch) | |
tree | 909e423e18dedf8efd7881fa5c151f1618a692b7 /source4/lib/ldb | |
parent | 2aeea4bb4d214675334da7c45e896d88ccb85832 (diff) | |
download | samba-ca34ffaaac4cc98dc600cb8b5bc6e8ecf93f7492.tar.gz samba-ca34ffaaac4cc98dc600cb8b5bc6e8ecf93f7492.tar.bz2 samba-ca34ffaaac4cc98dc600cb8b5bc6e8ecf93f7492.zip |
ldb:python bindings - some small cleanup & improvements in "py_ldb_add"
Also to make it similar to "py_ldb_delete".
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r-- | source4/lib/ldb/pyldb.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 7d999fa2e2..749ddd025a 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -710,14 +710,19 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "O|O", &py_msg, &py_controls )) return NULL; - ldb_ctx = PyLdb_AsLdbContext(self); mem_ctx = talloc_new(NULL); + if (mem_ctx == NULL) { + PyErr_NoMemory(); + return NULL; + } + ldb_ctx = PyLdb_AsLdbContext(self); + if (py_controls == Py_None) { parsed_controls = NULL; } else { - const char **controls = PyList_AsStringList(ldb_ctx, py_controls, "controls"); - parsed_controls = ldb_parse_control_strings(ldb_ctx, ldb_ctx, controls); + const char **controls = PyList_AsStringList(mem_ctx, py_controls, "controls"); + parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls); talloc_free(controls); } if (PyDict_Check(py_msg)) { @@ -770,13 +775,8 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args) return NULL; } - ret = ldb_build_add_req(&req, ldb_ctx, ldb_ctx, - msg, - parsed_controls, - NULL, - ldb_op_default_callback, - NULL); - + ret = ldb_build_add_req(&req, ldb_ctx, mem_ctx, msg, parsed_controls, + NULL, ldb_op_default_callback, NULL); if (ret != LDB_SUCCESS) { PyErr_SetString(PyExc_TypeError, "failed to build request"); talloc_free(mem_ctx); @@ -788,9 +788,8 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args) ret = ldb_transaction_start(ldb_ctx); if (ret != LDB_SUCCESS) { - talloc_free(req); talloc_free(mem_ctx); - PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, PyLdb_AsLdbContext(self)); + PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb_ctx); } ret = ldb_request(ldb_ctx, req); @@ -807,9 +806,9 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args) ldb_asprintf_errstring(ldb_ctx, "%s (%d)", ldb_strerror(ret), ret); } } - talloc_free(req); + talloc_free(mem_ctx); - PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, PyLdb_AsLdbContext(self)); + PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb_ctx); Py_RETURN_NONE; } |