From d806427f200dc1ffd44d37724eb40125af5cc8c2 Mon Sep 17 00:00:00 2001 From: Fabiano FidĂȘncio Date: Mon, 26 Sep 2016 01:15:56 +0200 Subject: SECRETS: Use a tmp_context on local_db_check_containers() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise the struct ldb_dn will be hanging on the mem_ctx till it gets freed. Signed-off-by: Fabiano FidĂȘncio Reviewed-by: Jakub Hrozek --- src/responder/secrets/local.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/responder/secrets/local.c b/src/responder/secrets/local.c index 0ce0526cf..484e40643 100644 --- a/src/responder/secrets/local.c +++ b/src/responder/secrets/local.c @@ -286,14 +286,21 @@ static int local_db_check_containers(TALLOC_CTX *mem_ctx, struct local_context *lctx, struct ldb_dn *leaf_dn) { + TALLOC_CTX *tmp_ctx; static const char *attrs[] = { NULL}; struct ldb_result *res = NULL; struct ldb_dn *dn; int num; int ret; - dn = ldb_dn_copy(mem_ctx, leaf_dn); - if (!dn) return ENOMEM; + tmp_ctx = talloc_new(mem_ctx); + if (!tmp_ctx) return ENOMEM; + + dn = ldb_dn_copy(tmp_ctx, leaf_dn); + if (!dn) { + ret = ENOMEM; + goto done; + } /* We need to exclude the leaf as that will be the new child entry, * We also do not care for the synthetic containers that constitute the @@ -306,14 +313,23 @@ static int local_db_check_containers(TALLOC_CTX *mem_ctx, if (!ldb_dn_remove_child_components(dn, 1)) return EFAULT; /* and check the parent container exists */ - ret = ldb_search(lctx->ldb, mem_ctx, &res, dn, LDB_SCOPE_BASE, + ret = ldb_search(lctx->ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE, attrs, LOCAL_CONTAINER_FILTER); - if (ret != LDB_SUCCESS) return ENOENT; - if (res->count != 1) return ENOENT; - talloc_free(res); + if (ret != LDB_SUCCESS) { + ret = ENOENT; + goto done; + } + if (res->count != 1) { + ret = ENOENT; + goto done; + } } - return EOK; + ret = EOK; + +done: + talloc_free(tmp_ctx); + return ret; } static int local_db_put_simple(TALLOC_CTX *mem_ctx, -- cgit