[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2] sockets: avoid leak of listen file descripto
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v2] sockets: avoid leak of listen file descriptor |
Date: |
Fri, 20 Oct 2017 15:14:40 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 |
On 10/20/2017 09:12 AM, Daniel P. Berrange wrote:
> If we iterate over the full port range without successfully binding+listening
> on the socket, we'll try the next address, whereupon we overwrite the slisten
> file descriptor variable without closing it.
>
> Rather than having two places where we open + close socket FDs on different
> iterations of nested for loops, re-arrange the code to always open+close
> within the same loop iteration.
>
> Signed-off-by: Daniel P. Berrange <address@hidden>
> ---
> util/qemu-sockets.c | 52 +++++++++++++++++++++++++++++-----------------------
> 1 file changed, 29 insertions(+), 23 deletions(-)
>
> + slisten = create_fast_reuse_socket(e);
> + if (slisten < 0) {
> + /* First time we expect we might fail to create the socket
> + * eg if 'e' has AF_INET6 but ipv6 kmod is not loaded.
> + * Later iterations should always succeeed if first iteration
s/succeeed/succeed/
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature