pyldb: Fix memory leak in Dn.concat.
authorJelmer Vernooij <jelmer@samba.org>
Wed, 17 Jun 2009 18:23:54 +0000 (20:23 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 17 Jun 2009 18:45:39 +0000 (20:45 +0200)
source4/lib/ldb/pyldb.c

index deeddd11fd04894a45327bd9beed186c9f858913..0f666a35f339967fc91b599f409dcc7a3cec6db7 100644 (file)
@@ -291,11 +291,20 @@ static PyObject *py_ldb_dn_concat(PyLdbDnObject *self, PyObject *py_other)
 {
        struct ldb_dn *dn = PyLdbDn_AsDn((PyObject *)self), 
                                  *other;
-       struct ldb_dn *ret = ldb_dn_copy(NULL, dn);
+       PyLdbDnObject *py_ret;
+       
        if (!PyObject_AsDn(NULL, py_other, NULL, &other))
                return NULL;
-       ldb_dn_add_child(ret, other);
-       return PyLdbDn_FromDn(ret);
+
+       py_ret = (PyLdbDnObject *)PyLdbDn.tp_alloc(&PyLdbDn, 0);
+       if (py_ret == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+       py_ret->mem_ctx = talloc_new(NULL);
+       py_ret->dn = ldb_dn_copy(py_ret->mem_ctx, dn);
+       ldb_dn_add_child(py_ret->dn, other);
+       return (PyObject *)py_ret;
 }
 
 static PySequenceMethods py_ldb_dn_seq = {