getaddrinfo: Fix resource leak after strdup failure in gethosts [BZ #25425]

Message ID 87eevuukon.fsf@oldenburg2.str.redhat.com
State Committed
Headers

Commit Message

Florian Weimer Jan. 20, 2020, 5 p.m. UTC
  Filip Ochnik spotted that one of the error jumps in gethosts fails to
call __resolv_context_put to release the resolver context.

Fixes commit 352f4ff9a268b81ef5d4b2413f582565806e4790 ("resolv:
Introduce struct resolv_context [BZ #21668]") and commit
964263bb8d650f1681665c55704fb01a8e725621 ("getaddrinfo: Release
resolver context on error in gethosts [BZ #21885]").

-----
 sysdeps/posix/getaddrinfo.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Siddhesh Poyarekar Jan. 20, 2020, 5:21 p.m. UTC | #1
On 20/01/20 10:30 pm, Florian Weimer wrote:
> Filip Ochnik spotted that one of the error jumps in gethosts fails to
> call __resolv_context_put to release the resolver context.
> 
> Fixes commit 352f4ff9a268b81ef5d4b2413f582565806e4790 ("resolv:
> Introduce struct resolv_context [BZ #21668]") and commit
> 964263bb8d650f1681665c55704fb01a8e725621 ("getaddrinfo: Release
> resolver context on error in gethosts [BZ #21885]").
> 
OK for master.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
  
Florian Weimer Jan. 20, 2020, 5:39 p.m. UTC | #2
* Siddhesh Poyarekar:

> On 20/01/20 10:30 pm, Florian Weimer wrote:
>> Filip Ochnik spotted that one of the error jumps in gethosts fails to
>> call __resolv_context_put to release the resolver context.
>> 
>> Fixes commit 352f4ff9a268b81ef5d4b2413f582565806e4790 ("resolv:
>> Introduce struct resolv_context [BZ #21668]") and commit
>> 964263bb8d650f1681665c55704fb01a8e725621 ("getaddrinfo: Release
>> resolver context on error in gethosts [BZ #21885]").
>> 
> OK for master.
>
> Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

Thanks, pushed.

Florian
  

Patch

diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index f813d85aa3..538691a598 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -288,6 +288,7 @@  convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
 	  canonbuf = __strdup (localcanon);				      \
 	  if (canonbuf == NULL)						      \
 	    {								      \
+	      __resolv_context_put (res_ctx);				      \
 	      result = -EAI_SYSTEM;					      \
 	      goto free_and_return;					      \
 	    }								      \