From 956678685325a79a315f4ef19c0d834fd1747e4c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 14 Aug 2012 16:08:47 +1000 Subject: s4-dsdb: Add mem_ctx argument to samdb_ntds_settings_dn As this value is calculated new each time, we need to give it a context to live on. If the value is the forced value during provision, a reference is taken. This was responsible for the memory leak in the replication process. In the example I was given, this DN appeared in memory 13596 times! Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Tue Aug 14 10:05:14 CEST 2012 on sn-devel-104 --- source4/dsdb/repl/drepl_fsmo.c | 8 +++++++- source4/dsdb/repl/drepl_partitions.c | 2 +- source4/dsdb/repl/drepl_ridalloc.c | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'source4/dsdb/repl') diff --git a/source4/dsdb/repl/drepl_fsmo.c b/source4/dsdb/repl/drepl_fsmo.c index db6385315b..4a1d08ac1b 100644 --- a/source4/dsdb/repl/drepl_fsmo.c +++ b/source4/dsdb/repl/drepl_fsmo.c @@ -77,8 +77,9 @@ NTSTATUS drepl_take_FSMO_role(struct irpc_message *msg, enum drepl_role_master role = r->in.role; struct fsmo_role_state *fsmo; - ntds_dn = samdb_ntds_settings_dn(service->samdb); + ntds_dn = samdb_ntds_settings_dn(service->samdb, tmp_ctx); if (!ntds_dn) { + talloc_free(tmp_ctx); r->out.result = WERR_DS_DRA_INTERNAL_ERROR; return NT_STATUS_OK; } @@ -86,6 +87,7 @@ NTSTATUS drepl_take_FSMO_role(struct irpc_message *msg, werr = dsdb_get_fsmo_role_info(tmp_ctx, service->samdb, role, &fsmo_role_dn, &role_owner_dn); if (!W_ERROR_IS_OK(werr)) { + talloc_free(tmp_ctx); r->out.result = werr; return NT_STATUS_OK; } @@ -106,6 +108,7 @@ NTSTATUS drepl_take_FSMO_role(struct irpc_message *msg, DEBUG(2,("Unknown role %u in role transfer\n", (unsigned)role)); r->out.result = WERR_DS_DRA_INTERNAL_ERROR; + talloc_free(tmp_ctx); return NT_STATUS_OK; } @@ -115,6 +118,7 @@ NTSTATUS drepl_take_FSMO_role(struct irpc_message *msg, ldb_dn_get_linearized(fsmo_role_dn), ldb_dn_get_linearized(role_owner_dn))); r->out.result = WERR_OK; + talloc_free(tmp_ctx); return NT_STATUS_OK; } @@ -134,11 +138,13 @@ NTSTATUS drepl_take_FSMO_role(struct irpc_message *msg, fsmo); if (!W_ERROR_IS_OK(werr)) { r->out.result = werr; + talloc_free(tmp_ctx); return NT_STATUS_OK; } /* mark this message to be answered later */ msg->defer_reply = true; dreplsrv_run_pending_ops(service); + talloc_free(tmp_ctx); return NT_STATUS_OK; } diff --git a/source4/dsdb/repl/drepl_partitions.c b/source4/dsdb/repl/drepl_partitions.c index 3aa715a92d..7464dc1554 100644 --- a/source4/dsdb/repl/drepl_partitions.c +++ b/source4/dsdb/repl/drepl_partitions.c @@ -52,7 +52,7 @@ WERROR dreplsrv_load_partitions(struct dreplsrv_service *s) tmp_ctx = talloc_new(s); W_ERROR_HAVE_NO_MEMORY(tmp_ctx); - ntds_dn = samdb_ntds_settings_dn(s->samdb); + ntds_dn = samdb_ntds_settings_dn(s->samdb, tmp_ctx); if (!ntds_dn) { DEBUG(1,(__location__ ": Unable to find ntds_dn: %s\n", ldb_errstring(s->samdb))); talloc_free(tmp_ctx); diff --git a/source4/dsdb/repl/drepl_ridalloc.c b/source4/dsdb/repl/drepl_ridalloc.c index 6dcd9efd8a..c817c319f2 100644 --- a/source4/dsdb/repl/drepl_ridalloc.c +++ b/source4/dsdb/repl/drepl_ridalloc.c @@ -95,7 +95,7 @@ static int drepl_ridalloc_pool_exhausted(struct ldb_context *ldb, *exhausted = false; *_alloc_pool = UINT64_MAX; - server_dn = ldb_dn_get_parent(tmp_ctx, samdb_ntds_settings_dn(ldb)); + server_dn = ldb_dn_get_parent(tmp_ctx, samdb_ntds_settings_dn(ldb, tmp_ctx)); if (!server_dn) { talloc_free(tmp_ctx); return ldb_operr(ldb); @@ -208,7 +208,7 @@ WERROR dreplsrv_ridalloc_check_rid_pool(struct dreplsrv_service *service) return WERR_DS_DRA_INTERNAL_ERROR; } - if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), fsmo_role_dn) == 0) { + if (ldb_dn_compare(samdb_ntds_settings_dn(ldb, tmp_ctx), fsmo_role_dn) == 0) { /* we are the RID Manager - no need to do a DRSUAPI_EXOP_FSMO_RID_ALLOC */ talloc_free(tmp_ctx); -- cgit