]> granicus.if.org Git - pdns/commitdiff
close socket if bind fails to fix coverity leak issues
authorMark Zealey <mark@markandruth.co.uk>
Mon, 13 Jan 2014 09:36:50 +0000 (11:36 +0200)
committerMark Zealey <mark@markandruth.co.uk>
Mon, 13 Jan 2014 09:36:50 +0000 (11:36 +0200)
pdns/nameserver.cc
pdns/tcpreceiver.cc

index 04d9027010c0158c859531bdedcc9e7fcc7949b7..1be9663ebad64be05155fafb405903b3941ae96f 100644 (file)
@@ -128,6 +128,7 @@ void UDPNameserver::bindIPv4()
 
     g_localaddresses.push_back(locala);
     if(::bind(s, (sockaddr*)&locala, locala.getSocklen()) < 0) {
+      close(s);
       if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-address-nonexist-fail") ) {
         L<<Logger::Error<<"IPv4 Address " << localname << " does not exist on this server - skipping UDP bind" << endl;
         continue;
@@ -224,6 +225,7 @@ void UDPNameserver::bindIPv6()
     }
     g_localaddresses.push_back(locala);
     if(::bind(s, (sockaddr*)&locala, sizeof(locala))<0) {
+      close(s);
       if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-ipv6-nonexist-fail") ) {
         L<<Logger::Error<<"IPv6 Address " << localname << " does not exist on this server - skipping UDP bind" << endl;
         continue;
index 2bc40f2c3d50cbb12931784b73dbdaa79c59a614..6f1e4b239d7925d0835fb997fb4eedfca7494a73 100644 (file)
@@ -1003,6 +1003,7 @@ TCPNameserver::TCPNameserver()
     }
     
     if(::bind(s, (sockaddr*)&local, local.getSocklen())<0) {
+      close(s);
       if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-address-nonexist-fail") ) {
         L<<Logger::Error<<"IPv4 Address " << *laddr << " does not exist on this server - skipping TCP bind" << endl;
         continue;
@@ -1043,6 +1044,7 @@ TCPNameserver::TCPNameserver()
       L<<Logger::Error<<"Failed to set IPv6 socket to IPv6 only, continuing anyhow: "<<strerror(errno)<<endl;
     }
     if(bind(s, (const sockaddr*)&local, local.getSocklen())<0) {
+      close(s);
       if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-ipv6-nonexist-fail") ) {
         L<<Logger::Error<<"IPv6 Address " << *laddr << " does not exist on this server - skipping TCP bind" << endl;
         continue;