Преглед на файлове

Solve memory leak from deleting sniffer too early

anon преди 4 години
родител
ревизия
02564e27bf
променени са 2 файла, в които са добавени 6 реда и са изтрити 2 реда
  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;
 }