]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Check the vector capacity before creating the TCP worker thread 4764/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 13 Dec 2016 09:35:10 +0000 (10:35 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 13 Dec 2016 09:35:10 +0000 (10:35 +0100)
pdns/dnsdist-tcp.cc

index 8e30f7dad2f6a0bbeab588bdf4677bf213c25518..69ea938785d278b986b2039543ec34a4cf8f8d5a 100644 (file)
@@ -94,18 +94,6 @@ void TCPClientCollection::addTCPClientThread()
     return;
   }
 
-  try {
-    thread t1(tcpClientThread, pipefds[0]);
-    t1.detach();
-  }
-  catch(const std::runtime_error& e) {
-    /* the thread creation failed, don't leak */
-    errlog("Error creating a TCP thread: %s", e.what());
-    close(pipefds[0]);
-    close(pipefds[1]);
-    return;
-  }
-
   {
     std::lock_guard<std::mutex> lock(d_mutex);
 
@@ -116,6 +104,18 @@ void TCPClientCollection::addTCPClientThread()
       return;
     }
 
+    try {
+      thread t1(tcpClientThread, pipefds[0]);
+      t1.detach();
+    }
+    catch(const std::runtime_error& e) {
+      /* the thread creation failed, don't leak */
+      errlog("Error creating a TCP thread: %s", e.what());
+      close(pipefds[0]);
+      close(pipefds[1]);
+      return;
+    }
+
     d_tcpclientthreads.push_back(pipefds[1]);
   }