From 7ebce759122eeda383d7d299ee577c75c0f9ac6e Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 29 Sep 2015 09:42:36 +0200 Subject: Return correct error code from bind() Closing the socket might overwrite errno so we need to save its value. --- common/network/TcpSocket.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 9ac1478c..a25ee244 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -469,8 +469,9 @@ TcpListener::TcpListener(const struct sockaddr *listenaddr, #endif if (bind(sock, &sa.u.sa, listenaddrlen) == -1) { + int e = errorNumber; closesocket(sock); - throw SocketException("failed to bind socket", errorNumber); + throw SocketException("failed to bind socket", e); } // - Set it to be a listening socket -- cgit v1.2.3