From 5f9a5ef262b4700b47bfb931b6b096f56aa56b15 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 15 Feb 2019 10:04:23 +0000 Subject: [PATCH] s4/param: Fix provision_get_schema leaking python object provision_get_schema returns a ldb_context object which is stored in a python object. As a result the parent python object is never decrefed and probably not released ever. Signed-off-by: Noel Power Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- source4/dsdb/schema/tests/schema_syntax.c | 1 + source4/libnet/libnet_vampire.c | 2 +- source4/param/provision.c | 12 ++++-------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/source4/dsdb/schema/tests/schema_syntax.c b/source4/dsdb/schema/tests/schema_syntax.c index 17e62010e70..b22e110db52 100644 --- a/source4/dsdb/schema/tests/schema_syntax.c +++ b/source4/dsdb/schema/tests/schema_syntax.c @@ -225,6 +225,7 @@ static bool torture_dsdb_syntax_tcase_teardown(struct torture_context *tctx, voi struct torture_dsdb_syntax *priv; priv = talloc_get_type_abort(data, struct torture_dsdb_syntax); + talloc_unlink(priv, priv->ldb); talloc_free(priv); return true; diff --git a/source4/libnet/libnet_vampire.c b/source4/libnet/libnet_vampire.c index 6167493c359..6374946244e 100644 --- a/source4/libnet/libnet_vampire.c +++ b/source4/libnet/libnet_vampire.c @@ -337,7 +337,7 @@ static WERROR libnet_vampire_cb_apply_schema(struct libnet_vampire_cb_state *s, DEBUG(0,("Failed to attach schema from local provision using remote prefixMap.")); return WERR_INTERNAL_ERROR; } - talloc_free(schema_ldb); + talloc_unlink(s, schema_ldb); } cycle_before_switching = lpcfg_parm_long(s->lp_ctx, NULL, diff --git a/source4/param/provision.c b/source4/param/provision.c index 47f296afcdd..85671f80b87 100644 --- a/source4/param/provision.c +++ b/source4/param/provision.c @@ -555,13 +555,9 @@ struct ldb_context *provision_get_schema(TALLOC_CTX *mem_ctx, py_ldb = PyObject_GetAttrString(py_result, "ldb"); Py_DECREF(py_result); ldb_result = pyldb_Ldb_AsLdbContext(py_ldb); - /* - * #TODO #FIXME There is a leak here !!! - * Looks like ldb is a new object returned from schema_fn - * We extract the ldb_ctx from that which rightly - * will be destoryed when py_ldb is decremented. - * Presently the ldb_context is returned (but the owning - * object is leaked) - */ + if (talloc_reference(mem_ctx, ldb_result) == NULL) { + ldb_result = NULL; + } + Py_DECREF(py_ldb); return ldb_result; } -- 2.34.1