sockets: avoid leak of listen file descriptor
commit10a7b7e6fd9f250f0506568345d7b4d2ab52889d
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 20 Oct 2017 09:18:39 +0000 (20 10:18 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 7 Nov 2017 14:10:20 +0000 (7 14:10 +0000)
tree960eb875f5637140e8aa3c4889b66e5cbe16e0a3
parent5853e92207193e967abf5e4c25b4a551c7604725
sockets: avoid leak of listen file descriptor

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.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
util/qemu-sockets.c