diff --git a/client/main.cpp b/client/main.cpp
index 07b073f..b9f7ae9 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -26,6 +26,8 @@ along with this program. If not, see
#include
#include
+#include
+
extern const char* version;
extern const char* revision;
extern ProtocolManager *OstProtocolManager;
@@ -76,8 +78,11 @@ int main(int argc, char* argv[])
mainWindow = new MainWindow;
mainWindow->show();
exitCode = app.exec();
+
delete mainWindow;
delete appSettings;
+ delete OstProtocolManager;
+ google::protobuf::ShutdownProtobufLibrary();
return exitCode;
}
diff --git a/server/drone_main.cpp b/server/drone_main.cpp
index e59cb48..64763cb 100644
--- a/server/drone_main.cpp
+++ b/server/drone_main.cpp
@@ -21,8 +21,10 @@ along with this program. If not, see
#include "../common/protocolmanager.h"
+#include
+
#ifdef Q_OS_UNIX
-#include "signal.h"
+#include
#endif
extern ProtocolManager *OstProtocolManager;
@@ -36,17 +38,21 @@ void cleanup(int /*signum*/)
int main(int argc, char *argv[])
{
+ int exitCode = 0;
QApplication app(argc, argv);
- Drone drone;
+ Drone *drone = new Drone();
OstProtocolManager = new ProtocolManager();
- app.setApplicationName(drone.objectName());
+ app.setApplicationName(drone->objectName());
if (argc > 1)
myport = atoi(argv[1]);
- if (!drone.init())
- exit(-1);
+ if (!drone->init())
+ {
+ exitCode = -1;
+ goto _exit;
+ }
#ifdef Q_OS_UNIX
struct sigaction sa;
@@ -58,14 +64,18 @@ int main(int argc, char *argv[])
qDebug("Failed to install SIGINT handler. Cleanup may not happen!!!");
#endif
- drone.setWindowFlags(drone.windowFlags()
+ drone->setWindowFlags(drone->windowFlags()
| Qt::WindowMaximizeButtonHint
| Qt::WindowMinimizeButtonHint);
- drone.showMinimized();
- app.exec();
+ drone->showMinimized();
+ exitCode = app.exec();
+_exit:
+ delete drone;
delete OstProtocolManager;
- return 0;
+ google::protobuf::ShutdownProtobufLibrary();
+
+ return exitCode;
}
diff --git a/server/linuxport.cpp b/server/linuxport.cpp
index 7e15101..12f5cb3 100644
--- a/server/linuxport.cpp
+++ b/server/linuxport.cpp
@@ -59,6 +59,12 @@ LinuxPort::~LinuxPort()
{
qDebug("In %s", __FUNCTION__);
+ if (monitor_->isRunning())
+ {
+ monitor_->stop();
+ monitor_->wait();
+ }
+
if (clearPromisc_)
{
int sd = socket(AF_INET, SOCK_DGRAM, 0);
@@ -114,6 +120,7 @@ bool LinuxPort::setExclusiveControl(bool /*exclusive*/)
LinuxPort::StatsMonitor::StatsMonitor()
: QThread()
{
+ stop_ = false;
}
void LinuxPort::StatsMonitor::run()
@@ -260,7 +267,7 @@ void LinuxPort::StatsMonitor::run()
//
// We are all set - Let's start polling for stats!
//
- while (1)
+ while (!stop_)
{
lseek(fd, 0, SEEK_SET);
len = read(fd, (void*) buf.data(), buf.size());
@@ -334,6 +341,12 @@ void LinuxPort::StatsMonitor::run()
}
QThread::sleep(kRefreshFreq_);
}
+
+ free(portStats);
}
+void LinuxPort::StatsMonitor::stop()
+{
+ stop_ = true;
+}
#endif
diff --git a/server/linuxport.h b/server/linuxport.h
index 4fe3305..817ece1 100644
--- a/server/linuxport.h
+++ b/server/linuxport.h
@@ -44,8 +44,10 @@ protected:
public:
StatsMonitor();
void run();
+ void stop();
private:
static const int kRefreshFreq_ = 1; // in seconds
+ bool stop_;
};
bool clearPromisc_;
diff --git a/server/pcapport.cpp b/server/pcapport.cpp
index 465b44c..cefffb3 100644
--- a/server/pcapport.cpp
+++ b/server/pcapport.cpp
@@ -324,6 +324,8 @@ PcapPort::PortTransmitter::~PortTransmitter()
{
if (usingInternalStats_)
delete stats_;
+ if (usingInternalHandle_)
+ pcap_close(handle_);
}
void PcapPort::PortTransmitter::clearPacketList()