ldb:python bindings - add a context on "py_ldb_delete"
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sun, 15 Nov 2009 13:23:32 +0000 (14:23 +0100)
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sun, 15 Nov 2009 13:26:41 +0000 (14:26 +0100)
So the converted DN will be freed after usage.

source4/lib/ldb/pyldb.c

index 901d121ff6cb1bf90794c674a270d46d0e008abe..1f1dcf8e316bca3ddd1ba2f1fb8fd57850ad1fab 100644 (file)
@@ -783,15 +783,23 @@ static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args)
        struct ldb_dn *dn;
        int ret;
        struct ldb_context *ldb;
        struct ldb_dn *dn;
        int ret;
        struct ldb_context *ldb;
+       TALLOC_CTX *mem_ctx;
        if (!PyArg_ParseTuple(args, "O", &py_dn))
                return NULL;
 
        if (!PyArg_ParseTuple(args, "O", &py_dn))
                return NULL;
 
+       mem_ctx = talloc_new(NULL);
+       if (mem_ctx == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
        ldb = PyLdb_AsLdbContext(self);
        ldb = PyLdb_AsLdbContext(self);
-
-       if (!PyObject_AsDn(NULL, py_dn, ldb, &dn))
+       if (!PyObject_AsDn(mem_ctx, py_dn, ldb, &dn)) {
+               talloc_free(mem_ctx);
                return NULL;
                return NULL;
+       }
 
        ret = ldb_delete(ldb, dn);
 
        ret = ldb_delete(ldb, dn);
+       talloc_free(mem_ctx);
        PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb);
 
        Py_RETURN_NONE;
        PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb);
 
        Py_RETURN_NONE;