7c0489
commit 8b222fa38700422b4da6731806835f0bbf40920d
7c0489
Author: Florian Weimer <fweimer@redhat.com>
7c0489
Date:   Mon Jan 20 18:37:13 2020 +0100
7c0489
7c0489
    getaddrinfo: Fix resource leak after strdup failure in gethosts [BZ #25425]
7c0489
    
7c0489
    Filip Ochnik spotted that one of the error jumps in gethosts fails to
7c0489
    call __resolv_context_put to release the resolver context.
7c0489
    
7c0489
    Fixes commit 352f4ff9a268b81ef5d4b2413f582565806e4790 ("resolv:
7c0489
    Introduce struct resolv_context [BZ #21668]") and commit
7c0489
    964263bb8d650f1681665c55704fb01a8e725621 ("getaddrinfo: Release
7c0489
    resolver context on error in gethosts [BZ #21885]").
7c0489
    
7c0489
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
7c0489
7c0489
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
7c0489
index 6a5805c9e63a257c..fae3dea81f19dba6 100644
7c0489
--- a/sysdeps/posix/getaddrinfo.c
7c0489
+++ b/sysdeps/posix/getaddrinfo.c
7c0489
@@ -292,6 +292,7 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
7c0489
 	  canonbuf = __strdup (localcanon);				      \
7c0489
 	  if (canonbuf == NULL)						      \
7c0489
 	    {								      \
7c0489
+	      __resolv_context_put (res_ctx);				      \
7c0489
 	      result = -EAI_SYSTEM;					      \
7c0489
 	      goto free_and_return;					      \
7c0489
 	    }								      \