From de503d8d9646f8982a6eb4d4ae4169d10a8c3fc3 Mon Sep 17 00:00:00 2001 From: Srivats P Date: Tue, 29 Nov 2016 18:20:00 +0530 Subject: [PATCH] sign: Fix crash when doing TX on a streamless port Ensure packetListSize_ is non zero to avoid division by zero. Also reset packetListSize_ to 0 in the constructor - call clearPacketList() to do this --- server/pcaptxthread.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/pcaptxthread.cpp b/server/pcaptxthread.cpp index b01e4bb..1bd5d97 100644 --- a/server/pcaptxthread.cpp +++ b/server/pcaptxthread.cpp @@ -38,9 +38,8 @@ PcapTxThread::PcapTxThread(const char *device) "This Win32 platform does not support performance counter"); #endif state_ = kNotStarted; - returnToQIdx_ = -1; - loopDelay_ = 0; stop_ = false; + clearPacketList(); handle_ = pcap_open_live(device, 64 /* FIXME */, 0, 1000 /* ms */, errbuf); if (handle_ == NULL) @@ -441,7 +440,11 @@ int PcapTxThread::sendQueueTransmit(pcap_t *p, void PcapTxThread::updateStreamStats() { - // Number of tx packets sent during last transmit + // If no packets in list, nothing to be done + if (!packetListSize_) + return; + + // Get number of tx packets sent during last transmit quint64 pkts = stats_->pkts > lastStats_.pkts ? stats_->pkts - lastStats_.pkts : stats_->pkts + (ULLONG_MAX - lastStats_.pkts); @@ -458,6 +461,7 @@ void PcapTxThread::updateStreamStats() qDebug("%s:", __FUNCTION__); qDebug("txPkts = %" PRIu64, pkts); + qDebug("packetListSize_ = %" PRIu64, packetListSize_); qDebug("c = %d, d = %d\n", c, d); int i;