diff options
| author | 2017-12-28 21:36:08 +0100 | |
|---|---|---|
| committer | 2017-12-28 21:47:35 +0100 | |
| commit | cb8897ae4d9cb26843af0bbef5ddfbe82da9eef0 (patch) | |
| tree | f946566ed5efb569499d21642cf3047fd2d5375d /src | |
| parent | Fix uninitialized variable access (diff) | |
| download | KVIrc-cb8897ae4d9cb26843af0bbef5ddfbe82da9eef0.tar.gz KVIrc-cb8897ae4d9cb26843af0bbef5ddfbe82da9eef0.tar.bz2 KVIrc-cb8897ae4d9cb26843af0bbef5ddfbe82da9eef0.zip | |
Fix some memory leaks
Diffstat (limited to 'src')
| -rw-r--r-- | src/kvirc/kernel/KviLagMeter.cpp | 37 | ||||
| -rw-r--r-- | src/kvirc/kernel/KviLagMeter.h | 9 |
2 files changed, 27 insertions, 19 deletions
diff --git a/src/kvirc/kernel/KviLagMeter.cpp b/src/kvirc/kernel/KviLagMeter.cpp index 80c35119b..6a6889cb1 100644 --- a/src/kvirc/kernel/KviLagMeter.cpp +++ b/src/kvirc/kernel/KviLagMeter.cpp @@ -1,10 +1,10 @@ //============================================================================= // // File : KviLagMeter.cpp -// Creation date : Fri Oct 18 13:31:36 CEST 1999 by Juanjo Álvarez +// Creation date : Fri Oct 18 13:31:36 CEST 1999 by Juanjo �lvarez // // This file is part of the KVIrc IRC client distribution -// Copyright (C) 1999 Juanjo Álvarez +// Copyright (C) 1999 Juanjo �lvarez // Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) // // This program is FREE software. You can redistribute it and/or @@ -65,6 +65,8 @@ KviLagMeter::~KviLagMeter() { if(m_pDeletionSignal) *m_pDeletionSignal = true; + + qDeleteAll(m_lCheckList); } unsigned int KviLagMeter::secondsSinceLastCompleted() @@ -131,11 +133,11 @@ void KviLagMeter::timerEvent(QTimerEvent *) // the last completed check has been completed a lot of time ago // do we have some checks on the queue ? - if(m_CheckList.size() > 0) + if(m_lCheckList.count() > 0) { // if the first registered check is not too outdated // we wait a little more for it to return - KviLagCheck * c = m_CheckList.front(); + KviLagCheck * c = m_lCheckList.first(); if(c) { if((tv.tv_sec - c->lSecs) <= 10) @@ -195,20 +197,20 @@ void KviLagMeter::lagCheckRegister(const char * key, unsigned int uReliability) if(_OUTPUT_PARANOIC) m_pConnection->console()->output(KVI_OUT_VERBOSE, __tr2qs("Registered lag check with reliability %u (%s)"), uReliability, key); - KviLagCheck * c = new KviLagCheck; + KviLagCheck * c = new KviLagCheck(); c->szKey = key; struct timeval tv; kvi_gettimeofday(&tv); c->lSecs = tv.tv_sec; c->lUSecs = tv.tv_usec; c->uReliability = uReliability <= 100 ? uReliability : 100; - m_CheckList.push_back(c); - while(m_CheckList.size() > 30) + m_lCheckList.append(c); + while(m_lCheckList.size() > 30) { // we're fried :/ // either our ping mechanism is not working // or the server is stoned... - m_CheckList.erase(m_CheckList.begin()); + delete m_lCheckList.takeFirst(); } } @@ -216,7 +218,7 @@ bool KviLagMeter::lagCheckComplete(const char * key) { // find this lag check KviLagCheck * c = nullptr; - for(auto cc : m_CheckList) + for(auto cc : m_lCheckList) { if(kvi_strEqualCS(cc->szKey.ptr(), key)) { @@ -226,9 +228,10 @@ bool KviLagMeter::lagCheckComplete(const char * key) } if(!c) return false; // not found + // kill any earlier lag checks (IRC is a sequential proto) - while(m_CheckList.front() != c) - m_CheckList.erase(m_CheckList.begin()); + while(m_lCheckList.first() != c) + delete m_lCheckList.takeFirst(); if(_OUTPUT_PARANOIC) m_pConnection->console()->output(KVI_OUT_VERBOSE, __tr2qs("Lag check completed (%s)"), key); @@ -262,7 +265,7 @@ bool KviLagMeter::lagCheckComplete(const char * key) m_tFirstOwnCheck = 0; m_uLastReliability = c->uReliability; - m_CheckList.erase(m_CheckList.begin()); + delete m_lCheckList.takeFirst(); return true; } @@ -272,7 +275,13 @@ void KviLagMeter::lagCheckAbort(const char * key) if(_OUTPUT_PARANOIC) m_pConnection->console()->output(KVI_OUT_VERBOSE, __tr2qs("Lag check aborted (%s)"), key); - for(auto c : m_CheckList) + QList<KviLagCheck *> lAborted; + + for(auto c : m_lCheckList) + { if(kvi_strEqualCS(c->szKey.ptr(), key)) - m_CheckList.erase(std::remove(m_CheckList.begin(), m_CheckList.end(), c), m_CheckList.end()); + lAborted.append(c); + } + + qDeleteAll(lAborted); } diff --git a/src/kvirc/kernel/KviLagMeter.h b/src/kvirc/kernel/KviLagMeter.h index 751a4f48b..6996ce896 100644 --- a/src/kvirc/kernel/KviLagMeter.h +++ b/src/kvirc/kernel/KviLagMeter.h @@ -3,10 +3,10 @@ //============================================================================= // // File : KviLagMeter.h -// Creation date : Fri Oct 18 13:30:26 CEST 1999 by Juanjo Álvarez +// Creation date : Fri Oct 18 13:30:26 CEST 1999 by Juanjo �lvarez // // This file is part of the KVIrc IRC client distribution -// Copyright (C) 1999 Juanjo Álvarez +// Copyright (C) 1999 Juanjo �lvarez // Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net) // // This program is FREE software. You can redistribute it and/or @@ -29,8 +29,7 @@ #include "KviCString.h" #include <QObject> - -#include <vector> +#include <QList> class KviIrcConnection; @@ -58,7 +57,7 @@ protected: unsigned int m_uLastEmittedLag; // last emitted lag long m_tLastCompleted; // time when the last lag was completed (gettimeofday!) unsigned int m_uLastReliability; // how much reliable was the last completed check ? - std::vector<KviLagCheck *> m_CheckList; + QList<KviLagCheck *> m_lCheckList; long m_tFirstOwnCheck; // time when the first ping after a completed check was sent long m_tLastOwnCheck; // time when the last ping was sent bool m_bOnAlarm; |
