Ver código fonte

Solve memory leak from deleting sniffer too early

anon 4 anos atrás
pai
commit
02564e27bf
2 arquivos alterados com 6 adições e 2 exclusões
  1. 4 1
      daemon/src/Sniffer.cpp
  2. 2 1
      daemon/src/main.cpp

+ 4 - 1
daemon/src/Sniffer.cpp

@@ -15,7 +15,10 @@ Sniffer::Sniffer(const std::string &interfaceName) {
   }
 }
 
-Sniffer::~Sniffer() {}
+Sniffer::~Sniffer() {
+  sniffer->stop_sniff();
+  delete (sniffer);
+}
 
 void Sniffer::startSniffing() {
   sniffer->sniff_loop(make_sniffer_handler(this, &Sniffer::handle));

+ 2 - 1
daemon/src/main.cpp

@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) {
   }
 
   const string interface = argv[1];
-  Sniffer sniffer(interface);
+  Sniffer *sniffer = new Sniffer(interface);
   thread snifferThread(&Sniffer::startSniffing, sniffer);
 
   try {
@@ -25,5 +25,6 @@ int main(int argc, char *argv[]) {
   }
 
   snifferThread.join();
+  delete (sniffer);
   return 0;
 }