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/common/util.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'source4/dsdb/common') diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index dca7a4409e..251e17759b 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -1241,7 +1241,7 @@ failed: /* work out the ntds settings dn for the current open ldb */ -struct ldb_dn *samdb_ntds_settings_dn(struct ldb_context *ldb) +struct ldb_dn *samdb_ntds_settings_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx) { TALLOC_CTX *tmp_ctx; const char *root_attrs[] = { "dsServiceName", NULL }; @@ -1252,10 +1252,10 @@ struct ldb_dn *samdb_ntds_settings_dn(struct ldb_context *ldb) /* see if we have a cached copy */ settings_dn = (struct ldb_dn *)ldb_get_opaque(ldb, "forced.ntds_settings_dn"); if (settings_dn) { - return settings_dn; + return talloc_reference(mem_ctx, settings_dn); } - tmp_ctx = talloc_new(ldb); + tmp_ctx = talloc_new(mem_ctx); if (tmp_ctx == NULL) { goto failed; } @@ -1277,7 +1277,7 @@ struct ldb_dn *samdb_ntds_settings_dn(struct ldb_context *ldb) * we could not handle server renames at runtime. Only * provision sets up forced.ntds_settings_dn */ - talloc_steal(ldb, settings_dn); + talloc_steal(mem_ctx, settings_dn); talloc_free(tmp_ctx); return settings_dn; @@ -1310,7 +1310,7 @@ const struct GUID *samdb_ntds_invocation_id(struct ldb_context *ldb) goto failed; } - ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, attrs, NULL); + ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb, tmp_ctx), LDB_SCOPE_BASE, attrs, NULL); if (ret) { goto failed; } @@ -1403,7 +1403,7 @@ const struct GUID *samdb_ntds_objectGUID(struct ldb_context *ldb) goto failed; } - ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, attrs, NULL); + ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb, tmp_ctx), LDB_SCOPE_BASE, attrs, NULL); if (ret) { goto failed; } @@ -1478,7 +1478,15 @@ failed: */ struct ldb_dn *samdb_server_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx) { - return ldb_dn_get_parent(mem_ctx, samdb_ntds_settings_dn(ldb)); + TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); + struct ldb_dn *dn; + if (!tmp_ctx) { + return NULL; + } + dn = ldb_dn_get_parent(mem_ctx, samdb_ntds_settings_dn(ldb, tmp_ctx)); + talloc_free(tmp_ctx); + return dn; + } /* @@ -1798,7 +1806,7 @@ bool samdb_is_pdc(struct ldb_context *ldb) goto failed; } - if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), pdc) == 0) { + if (ldb_dn_compare(samdb_ntds_settings_dn(ldb, tmp_ctx), pdc) == 0) { is_pdc = true; } else { is_pdc = false; @@ -2981,7 +2989,7 @@ int samdb_ntds_options(struct ldb_context *ldb, uint32_t *options) goto failed; } - ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, attrs, NULL); + ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb, tmp_ctx), LDB_SCOPE_BASE, attrs, NULL); if (ret != LDB_SUCCESS) { goto failed; } @@ -3008,7 +3016,7 @@ const char* samdb_ntds_object_category(TALLOC_CTX *tmp_ctx, struct ldb_context * int ret; struct ldb_result *res; - ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, attrs, NULL); + ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb, tmp_ctx), LDB_SCOPE_BASE, attrs, NULL); if (ret != LDB_SUCCESS) { goto failed; } -- cgit