From 4d2baca7be36d7cccbb2c632598a4e43ca1dd55e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 17 Jun 2009 20:32:35 +0200 Subject: pyldb: Fix memory leak in Dn.get_parent(). --- source4/lib/ldb/pyldb.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'source4') diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 0f666a35f3..13706807be 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -207,10 +207,24 @@ static PyObject *py_ldb_dn_get_parent(PyLdbDnObject *self) { struct ldb_dn *dn = PyLdbDn_AsDn((PyObject *)self); struct ldb_dn *parent; + PyLdbDnObject *py_ret; + TALLOC_CTX *mem_ctx = talloc_new(NULL); - parent = ldb_dn_get_parent(NULL, dn); + parent = ldb_dn_get_parent(mem_ctx, dn); + if (parent == NULL) { + talloc_free(mem_ctx); + Py_RETURN_NONE; + } - return PyLdbDn_FromDn(parent); + py_ret = (PyLdbDnObject *)PyLdbDn.tp_alloc(&PyLdbDn, 0); + if (py_ret == NULL) { + PyErr_NoMemory(); + talloc_free(mem_ctx); + return NULL; + } + py_ret->mem_ctx = mem_ctx; + py_ret->dn = parent; + return (PyObject *)py_ret; } #define dn_ldb_ctx(dn) ((struct ldb_context *)dn) -- cgit