diff --git a/client/port.cpp b/client/port.cpp index 2509927..fd091f4 100644 --- a/client/port.cpp +++ b/client/port.cpp @@ -22,6 +22,8 @@ Port::Port(quint32 id, quint32 portGroupId) Port::~Port() { + while (!mStreams.isEmpty()) + delete mStreams.takeFirst(); } void Port::updatePortConfig(OstProto::Port *port) diff --git a/client/port.h b/client/port.h index 06162a0..2c36660 100644 --- a/client/port.h +++ b/client/port.h @@ -13,8 +13,9 @@ class Port : public QObject { Q_OBJECT static uint mAllocStreamId; + OstProto::Port d; - OstProto::PortStats stats; + OstProto::PortStats stats; // FIXME(HI): consider removing mPortId as it is duplicated inside 'd' quint32 mPortId; diff --git a/client/portgroup.cpp b/client/portgroup.cpp index 8705224..ba5364c 100644 --- a/client/portgroup.cpp +++ b/client/portgroup.cpp @@ -23,8 +23,7 @@ PortGroup::PortGroup(QHostAddress ip, quint16 port) rpcController = new PbRpcController; rpcControllerStats = new PbRpcController; isGetStatsPending_ = false; - serviceStub = new OstProto::OstService::Stub(rpcChannel, - OstProto::OstService::STUB_OWNS_CHANNEL); + serviceStub = new OstProto::OstService::Stub(rpcChannel); // FIXME(LOW):Can't for my life figure out why this ain't working! //QMetaObject::connectSlotsByName(this); @@ -44,6 +43,9 @@ PortGroup::~PortGroup() // Disconnect and free rpc channel etc. PortGroup::disconnectFromHost(); delete serviceStub; + delete rpcControllerStats; + delete rpcController; + delete rpcChannel; } diff --git a/client/portgrouplist.cpp b/client/portgrouplist.cpp index 49aa539..b76fb15 100644 --- a/client/portgrouplist.cpp +++ b/client/portgrouplist.cpp @@ -11,15 +11,25 @@ PortGroupList::PortGroupList() PortGroup *pg; // TODO(LOW): Remove - new ModelTest(getStreamModel()); - new ModelTest(getPortModel()); - new ModelTest(getPortStatsModel()); + streamModelTester_ = new ModelTest(getStreamModel()); + portModelTester_ = new ModelTest(getPortModel()); + portStatsModelTester_ = new ModelTest(getPortStatsModel()); // Add the "Local" Port Group pg = new PortGroup; addPortGroup(*pg); } +PortGroupList::~PortGroupList() +{ + while (!mPortGroups.isEmpty()) + delete mPortGroups.takeFirst(); + + delete portStatsModelTester_; + delete portModelTester_; + delete streamModelTester_; +} + bool PortGroupList::isPortGroup(const QModelIndex& index) { return mPortGroupListModel.isPortGroup(index); diff --git a/client/portgrouplist.h b/client/portgrouplist.h index 3dd8f5f..e8d2433 100644 --- a/client/portgrouplist.h +++ b/client/portgrouplist.h @@ -21,13 +21,17 @@ class PortGroupList : public QObject { QList mPortGroups; PortModel mPortGroupListModel; - StreamModel mStreamListModel; - PortStatsModel mPortStatsModel; + StreamModel mStreamListModel; + PortStatsModel mPortStatsModel; + + QObject *streamModelTester_; + QObject *portModelTester_; + QObject *portStatsModelTester_; // Methods public: PortGroupList(); - + ~PortGroupList(); PortModel* getPortModel() { return &mPortGroupListModel; } PortStatsModel* getPortStatsModel() { return &mPortStatsModel; } diff --git a/client/portstatsmodel.cpp b/client/portstatsmodel.cpp index 72b3d16..cc76c1f 100644 --- a/client/portstatsmodel.cpp +++ b/client/portstatsmodel.cpp @@ -6,8 +6,6 @@ PortStatsModel::PortStatsModel(PortGroupList *p, QObject *parent) : QAbstractTableModel(parent) { - QTimer *timer; - pgl = p; timer = new QTimer(); @@ -15,6 +13,12 @@ PortStatsModel::PortStatsModel(PortGroupList *p, QObject *parent) timer->start(1000); } +PortStatsModel::~PortStatsModel() +{ + timer->stop(); + delete timer; +} + int PortStatsModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) diff --git a/client/portstatsmodel.h b/client/portstatsmodel.h index 3baa7c2..0a2e3aa 100644 --- a/client/portstatsmodel.h +++ b/client/portstatsmodel.h @@ -4,6 +4,8 @@ #include #include +class QTimer; + typedef enum { // State e_STATE_START = 0, @@ -78,6 +80,7 @@ class PortStatsModel : public QAbstractTableModel public: PortStatsModel(PortGroupList *p, QObject *parent = 0); + ~PortStatsModel(); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -109,6 +112,8 @@ class PortStatsModel : public QAbstractTableModel // Also it stores them as cumulative totals QList numPorts; + QTimer *timer; + void getDomainIndexes(const QModelIndex &index, uint &portGroupIdx, uint &portIdx) const; diff --git a/client/portswindow.cpp b/client/portswindow.cpp index 22ae629..505891f 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -1,13 +1,15 @@ #include "portswindow.h" -#include "streamlistdelegate.h" -#include "streamconfigdialog.h" + #include #include +#include "streamconfigdialog.h" +#include "streamlistdelegate.h" + PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent) : QWidget(parent) { - StreamListDelegate *delegate = new StreamListDelegate; + delegate = new StreamListDelegate; //slm = new StreamListModel(); //plm = new PortGroupList(); plm = pgl; @@ -72,6 +74,7 @@ PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent) PortsWindow::~PortsWindow() { + delete delegate; } void PortsWindow::on_tvStreamList_activated(const QModelIndex & index) diff --git a/client/portswindow.h b/client/portswindow.h index c6db222..e327c49 100644 --- a/client/portswindow.h +++ b/client/portswindow.h @@ -12,6 +12,7 @@ MED LOW */ +class QAbstractItemDelegate; class PortsWindow : public QWidget, private Ui::PortsWindow { @@ -26,6 +27,7 @@ public: private: QString lastNewPortGroup; + QAbstractItemDelegate *delegate; void updatePortViewActions(const QModelIndex& current); //void updateStreamViewActions(const QModelIndex& current); diff --git a/common/protocolmanager.cpp b/common/protocolmanager.cpp index eb948ba..faaef8f 100644 --- a/common/protocolmanager.cpp +++ b/common/protocolmanager.cpp @@ -62,6 +62,16 @@ ProtocolManager::ProtocolManager() populateNeighbourProtocols(); } +ProtocolManager::~ProtocolManager() +{ + numberToNameMap.clear(); + nameToNumberMap.clear(); + neighbourProtocols.clear(); + factory.clear(); + while (!protocolList.isEmpty()) + delete protocolList.takeFirst(); +} + void ProtocolManager::registerProtocol(int protoNumber, void *protoInstanceCreator) { diff --git a/common/protocolmanager.h b/common/protocolmanager.h index 86ccf5d..c80315e 100644 --- a/common/protocolmanager.h +++ b/common/protocolmanager.h @@ -19,6 +19,7 @@ class ProtocolManager public: ProtocolManager(); + ~ProtocolManager(); void registerProtocol(int protoNumber, void *protoInstanceCreator); diff --git a/common/streambase.cpp b/common/streambase.cpp index 671f4d3..a7320ee 100644 --- a/common/streambase.cpp +++ b/common/streambase.cpp @@ -50,9 +50,11 @@ StreamBase::StreamBase() : StreamBase::~StreamBase() { - delete mStreamId; - delete mCore; + currentFrameProtocols->destroy(); + delete currentFrameProtocols; delete mControl; + delete mCore; + delete mStreamId; } void StreamBase::protoDataCopyFrom(const OstProto::Stream &stream) diff --git a/rpc/rpcserver.cpp b/rpc/rpcserver.cpp index 73f6f51..c989946 100644 --- a/rpc/rpcserver.cpp +++ b/rpc/rpcserver.cpp @@ -10,6 +10,7 @@ RpcServer::RpcServer() isPending = false; pendingMethodId = -1; // don't care as long as isPending is false + controller_.Reset(); } RpcServer::~RpcServer() @@ -46,21 +47,22 @@ QString RpcServer::errorString() return errorString_; } -void RpcServer::done(::google::protobuf::Message *resp, PbRpcController *PbRpcController) +void RpcServer::done(::google::protobuf::Message *request, + ::google::protobuf::Message *response) { - QIODevice *blob; - char msg[MSGBUF_SIZE]; - int len; + QIODevice *blob; + char msg[MSGBUF_SIZE]; + int len; //qDebug("In RpcServer::done"); - if (PbRpcController->Failed()) + if (controller_.Failed()) { qDebug("rpc failed"); goto _exit; } - blob = PbRpcController->binaryBlob(); + blob = controller_.binaryBlob(); if (blob) { len = blob->size(); @@ -85,17 +87,17 @@ void RpcServer::done(::google::protobuf::Message *resp, PbRpcController *PbRpcCo goto _exit; } - if (!resp->IsInitialized()) + if (!response->IsInitialized()) { qWarning("response missing required fields!!"); - qDebug(resp->InitializationErrorString().c_str()); + qDebug(response->InitializationErrorString().c_str()); qFatal("exiting"); goto _exit; } - resp->SerializeToArray((void*) &msg[PB_HDR_SIZE], sizeof(msg)); + response->SerializeToArray((void*) &msg[PB_HDR_SIZE], sizeof(msg)); - len = resp->ByteSize(); + len = response->ByteSize(); *((quint16*)(&msg[0])) = HTONS(PB_MSG_TYPE_RESPONSE); // type *((quint16*)(&msg[2])) = HTONS(pendingMethodId); // method @@ -105,14 +107,15 @@ void RpcServer::done(::google::protobuf::Message *resp, PbRpcController *PbRpcCo if (pendingMethodId != 12) { qDebug("Server(%s): sending %d bytes to client encoding <%s>", - __FUNCTION__, len + PB_HDR_SIZE, resp->DebugString().c_str()); + __FUNCTION__, len + PB_HDR_SIZE, response->DebugString().c_str()); //BUFDUMP(msg, len + 8); } clientSock->write(msg, PB_HDR_SIZE + len); _exit: - delete PbRpcController; + delete request; + delete response; isPending = false; } @@ -173,7 +176,6 @@ void RpcServer::when_dataAvail() static quint32 len; const ::google::protobuf::MethodDescriptor *methodDesc; ::google::protobuf::Message *req, *resp; - PbRpcController *controller; if (!parsing) { @@ -238,12 +240,12 @@ void RpcServer::when_dataAvail() //qDebug("Server(%s): successfully parsed as <%s>", __FUNCTION__, //resp->DebugString().c_str()); - controller = new PbRpcController; + controller_.Reset(); //qDebug("before service->callmethod()"); - service->CallMethod(methodDesc, controller, req, resp, - NewCallback(this, &RpcServer::done, resp, controller)); + service->CallMethod(methodDesc, &controller_, req, resp, + NewCallback(this, &RpcServer::done, req, resp)); parsing = false; diff --git a/rpc/rpcserver.h b/rpc/rpcserver.h index f4be419..9b8cd23 100644 --- a/rpc/rpcserver.h +++ b/rpc/rpcserver.h @@ -16,13 +16,14 @@ class RpcServer : public QObject { Q_OBJECT - QTcpServer *server; - QTcpSocket *clientSock; + QTcpServer *server; + QTcpSocket *clientSock; - ::google::protobuf::Service *service; + ::google::protobuf::Service *service; - bool isPending; - int pendingMethodId; + bool isPending; + int pendingMethodId; + PbRpcController controller_; QString errorString_; public: @@ -32,7 +33,8 @@ public: bool registerService(::google::protobuf::Service *service, quint16 tcpPortNum); QString errorString(); - void done(::google::protobuf::Message *resp, PbRpcController *controller); + void done(::google::protobuf::Message *req, + ::google::protobuf::Message *resp); private slots: void when_newConnection(); diff --git a/server/drone.cpp b/server/drone.cpp index 9dcccc8..0e03b29 100644 --- a/server/drone.cpp +++ b/server/drone.cpp @@ -20,6 +20,9 @@ Drone::Drone(QWidget *parent) Drone::~Drone() { trayIcon_->hide(); + + delete trayIcon_; + delete trayIconMenu_; delete rpcServer; delete service; } diff --git a/server/pcapport.cpp b/server/pcapport.cpp index ced12ab..ce576f2 100644 --- a/server/pcapport.cpp +++ b/server/pcapport.cpp @@ -195,6 +195,12 @@ _open_error: usingInternalHandle_ = false; } +PcapPort::PortTransmitter::~PortTransmitter() +{ + if (usingInternalStats_) + delete stats_; +} + void PcapPort::PortTransmitter::clearPacketList() { Q_ASSERT(!isRunning()); diff --git a/server/pcapport.h b/server/pcapport.h index 28e9499..423d15f 100644 --- a/server/pcapport.h +++ b/server/pcapport.h @@ -69,6 +69,7 @@ protected: { public: PortTransmitter(const char *device); + ~PortTransmitter(); void clearPacketList(); bool appendToPacketList(long sec, long usec, const uchar *packet, int length); diff --git a/server/portmanager.cpp b/server/portmanager.cpp index 1877234..bec541f 100644 --- a/server/portmanager.cpp +++ b/server/portmanager.cpp @@ -45,6 +45,8 @@ PortManager::PortManager() PortManager::~PortManager() { + while (!portList_.isEmpty()) + delete portList_.takeFirst(); } PortManager* PortManager::instance() diff --git a/server/winpcapport.cpp b/server/winpcapport.cpp index b6e536d..8afefba 100644 --- a/server/winpcapport.cpp +++ b/server/winpcapport.cpp @@ -24,6 +24,8 @@ WinPcapPort::WinPcapPort(int id, const char *device) WinPcapPort::~WinPcapPort() { + delete monitorRx_; + delete monitorTx_; } OstProto::LinkState WinPcapPort::linkState()