From 2599f5313bd86b9821ba38dd0b9679b5aaa50acc Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 15 Mar 2022 12:04:34 +0100 Subject: [PATCH] s3:libads: Leave early on error in get_kdc_ip_string() This avoids useless allocations. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15016 Signed-off-by: Andreas Schneider Reviewed-by: Guenther Deschner (cherry picked from commit 313f03c78487ae49747b8143220ecbfe8ad9310a) --- source3/libads/kerberos.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c index 60fe03fd5d7..1bf149ef09b 100644 --- a/source3/libads/kerberos.c +++ b/source3/libads/kerberos.c @@ -434,9 +434,14 @@ static char *get_kdc_ip_string(char *mem_ctx, struct netlogon_samlogon_response **responses = NULL; NTSTATUS status; bool ok; - char *kdc_str = talloc_asprintf(mem_ctx, "%s\t\tkdc = %s\n", "", - print_canonical_sockaddr_with_port(mem_ctx, pss)); + char *kdc_str = NULL; + SMB_ASSERT(pss != NULL); + + kdc_str = talloc_asprintf(mem_ctx, + "\t\tkdc = %s\n", + print_canonical_sockaddr_with_port(mem_ctx, + pss)); if (kdc_str == NULL) { TALLOC_FREE(frame); return NULL; @@ -516,15 +521,15 @@ static char *get_kdc_ip_string(char *mem_ctx, } } - dc_addrs2 = talloc_zero_array(talloc_tos(), - struct tsocket_address *, - num_dcs); - DBG_DEBUG("%zu additional KDCs to test\n", num_dcs); if (num_dcs == 0) { TALLOC_FREE(kdc_str); goto out; } + + dc_addrs2 = talloc_zero_array(talloc_tos(), + struct tsocket_address *, + num_dcs); if (dc_addrs2 == NULL) { TALLOC_FREE(kdc_str); goto out;