From 0c3769e181c09f45861f3b9f1d05cad8423372c3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 17 Jun 2009 20:23:54 +0200 Subject: pyldb: Fix memory leak in Dn.concat. --- source4/lib/ldb/pyldb.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index deeddd11fd..0f666a35f3 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -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 = { -- cgit