summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/pyldb.c27
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;
}