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