From: Remi Gacogne Date: Sun, 4 Dec 2016 20:09:37 +0000 (+0100) Subject: dnsdist: Add the TCP socket to the map only if the connection succeeds X-Git-Tag: dnsdist-1.1.0-beta2~27^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F4734%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Add the TCP socket to the map only if the connection succeeds Otherwise we create a value-initialized (to 0) entry in the map and try to use it later. --- diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 2e01da518d..9d9f956872 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -340,7 +340,8 @@ void* tcpClientThread(int pipefd) int dsock = -1; if(sockets.count(ds->remote) == 0) { - dsock=sockets[ds->remote]=setupTCPDownstream(ds); + dsock=setupTCPDownstream(ds); + sockets[ds->remote]=dsock; } else dsock=sockets[ds->remote]; @@ -369,7 +370,8 @@ void* tcpClientThread(int pipefd) close(dsock); dsock=-1; sockets.erase(ds->remote); - sockets[ds->remote]=dsock=setupTCPDownstream(ds); + dsock=setupTCPDownstream(ds); + sockets[ds->remote]=dsock; downstream_failures++; goto retry; } @@ -387,7 +389,8 @@ void* tcpClientThread(int pipefd) close(dsock); dsock=-1; sockets.erase(ds->remote); - sockets[ds->remote]=dsock=setupTCPDownstream(ds); + dsock=setupTCPDownstream(ds); + sockets[ds->remote]=dsock; downstream_failures++; goto retry; } @@ -405,7 +408,8 @@ void* tcpClientThread(int pipefd) close(dsock); dsock=-1; sockets.erase(ds->remote); - sockets[ds->remote]=dsock=setupTCPDownstream(ds); + dsock=setupTCPDownstream(ds); + sockets[ds->remote]=dsock; downstream_failures++; if(xfrStarted) { goto drop;