From: Volker Lendecke Date: Tue, 22 Sep 2020 11:52:57 +0000 (+0200) Subject: libsmb: Use talloc_realloc() correctly in resolve_hosts() X-Git-Tag: talloc-2.3.2~450 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c6a11d8dcda60e0854b6cd667a4f40a057256eb7;p=thirdparty%2Fsamba.git libsmb: Use talloc_realloc() correctly in resolve_hosts() On realloc failure the old value is still around Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index bb43cb2f615..1812e9b8bd0 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -2819,6 +2819,7 @@ static NTSTATUS resolve_hosts(TALLOC_CTX *mem_ctx, for (res = ailist; res; res = res->ai_next) { struct sockaddr_storage ss = {0}; + struct sockaddr_storage *tmp = NULL; if ((res->ai_addr == NULL) || (res->ai_addrlen == 0) || @@ -2839,14 +2840,15 @@ static NTSTATUS resolve_hosts(TALLOC_CTX *mem_ctx, } ret_count += 1; - iplist = talloc_realloc( + tmp = talloc_realloc( mem_ctx, iplist, struct sockaddr_storage, ret_count); - if (iplist == NULL) { + if (tmp == NULL) { DEBUG(3,("resolve_hosts: malloc fail !\n")); freeaddrinfo(ailist); return NT_STATUS_NO_MEMORY; } + iplist = tmp; iplist[i] = ss; i++; }