summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-08-14 15:56:04 +1000
committerAndrew Bartlett <abartlet@samba.org>2012-08-14 08:27:19 +0200
commit77990c183155d3bacbb5dae7f276ed7c2081553a (patch)
tree4a14d3f2ade2ef0f941d5ba00aefa1615e38bbcc
parentf74e7b5606b8c8281acac66973a8f48e6fd85a78 (diff)
downloadsamba-77990c183155d3bacbb5dae7f276ed7c2081553a.tar.gz
samba-77990c183155d3bacbb5dae7f276ed7c2081553a.tar.bz2
samba-77990c183155d3bacbb5dae7f276ed7c2081553a.zip
s4-dsdb: Improve memory handling in kccsrv_find_connections() by adding a tmp_ctx
-rw-r--r--source4/dsdb/kcc/kcc_connection.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/source4/dsdb/kcc/kcc_connection.c b/source4/dsdb/kcc/kcc_connection.c
index 1c4ebb1581..a5894c1a88 100644
--- a/source4/dsdb/kcc/kcc_connection.c
+++ b/source4/dsdb/kcc/kcc_connection.c
@@ -184,32 +184,41 @@ struct kcc_connection_list *kccsrv_find_connections(struct kccsrv_service *s,
struct ldb_result *res;
const char *attrs[] = { "objectGUID", "fromServer", NULL };
struct kcc_connection_list *list;
-
+ TALLOC_CTX *tmp_ctx;
kcctpl_test(s);
+ tmp_ctx = talloc_new(mem_ctx);
+ if (!tmp_ctx) {
+ DEBUG(0, ("failed to talloc\n"));
+ return NULL;
+ }
+
base_dn = samdb_ntds_settings_dn(s->samdb);
if (!base_dn) {
DEBUG(0, ("failed to find our own NTDS settings DN\n"));
+ talloc_free(tmp_ctx);
return NULL;
}
- ret = ldb_search(s->samdb, mem_ctx, &res, base_dn, LDB_SCOPE_ONELEVEL,
+ ret = ldb_search(s->samdb, tmp_ctx, &res, base_dn, LDB_SCOPE_ONELEVEL,
attrs, "objectClass=nTDSConnection");
if (ret != LDB_SUCCESS) {
DEBUG(0, ("failed nTDSConnection search: %s\n",
ldb_strerror(ret)));
+ talloc_free(tmp_ctx);
return NULL;
}
- list = talloc(mem_ctx, struct kcc_connection_list);
+ list = talloc(tmp_ctx, struct kcc_connection_list);
if (!list) {
DEBUG(0, ("out of memory"));
return NULL;
}
- list->servers = talloc_array(mem_ctx, struct kcc_connection,
+ list->servers = talloc_array(list, struct kcc_connection,
res->count);
if (!list->servers) {
DEBUG(0, ("out of memory"));
+ talloc_free(tmp_ctx);
return NULL;
}
list->count = 0;
@@ -233,5 +242,7 @@ struct kcc_connection_list *kccsrv_find_connections(struct kccsrv_service *s,
list->count++;
}
DEBUG(4, ("found %d existing nTDSConnection objects\n", list->count));
+ talloc_steal(mem_ctx, list);
+ talloc_free(tmp_ctx);
return list;
}