Message ID | 1486249715-5513-4-git-send-email-peter.maydell@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | slirp: fix 3 easy coverity warnings | expand |
On 02/04/2017 08:08 PM, Peter Maydell wrote: > Coverity points out (CID 1005725) that an error-exit path in tcp_listen() > will try to close(s) even if the reason it got there was that the > qemu_socket() failed and s was never opened. Not only that, this isn't even > the right function to use, because we need closesocket() to do the right > thing on Windows. Change to using the right function and only calling it if > needed. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > slirp/socket.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/slirp/socket.c b/slirp/socket.c > index 6c18971..8692772 100644 > --- a/slirp/socket.c > +++ b/slirp/socket.c > @@ -713,7 +713,9 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, > (listen(s,1) < 0)) { > int tmperrno = errno; /* Don't clobber the real reason we failed */ > > - close(s); > + if (s >= 0) { > + closesocket(s); > + } > sofree(so); > /* Restore the real errno */ > #ifdef _WIN32 >
diff --git a/slirp/socket.c b/slirp/socket.c index 6c18971..8692772 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -713,7 +713,9 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, (listen(s,1) < 0)) { int tmperrno = errno; /* Don't clobber the real reason we failed */ - close(s); + if (s >= 0) { + closesocket(s); + } sofree(so); /* Restore the real errno */ #ifdef _WIN32
Coverity points out (CID 1005725) that an error-exit path in tcp_listen() will try to close(s) even if the reason it got there was that the qemu_socket() failed and s was never opened. Not only that, this isn't even the right function to use, because we need closesocket() to do the right thing on Windows. Change to using the right function and only calling it if needed. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> --- slirp/socket.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.1.4