diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-30 01:58:37 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-30 01:58:37 +0000 |
commit | 3e1547e19140f9acda5035fdc25a9001b335dad7 (patch) | |
tree | 9ae140747431acfc364113dfab0088b1026eef73 | |
parent | 92485563d0e0ea384fbe3a411e815adbc88f7ba8 (diff) | |
download | chromium_src-3e1547e19140f9acda5035fdc25a9001b335dad7.zip chromium_src-3e1547e19140f9acda5035fdc25a9001b335dad7.tar.gz chromium_src-3e1547e19140f9acda5035fdc25a9001b335dad7.tar.bz2 |
Fix memory leak in remoting_unittests.
BUG=None
TEST=valgrind is happy.
Review URL: http://codereview.chromium.org/7283033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91077 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | remoting/jingle_glue/fake_signal_strategy.cc | 42 | ||||
-rw-r--r-- | remoting/jingle_glue/fake_signal_strategy.h | 5 |
2 files changed, 30 insertions, 17 deletions
diff --git a/remoting/jingle_glue/fake_signal_strategy.cc b/remoting/jingle_glue/fake_signal_strategy.cc index 98cfc42..be7c14b 100644 --- a/remoting/jingle_glue/fake_signal_strategy.cc +++ b/remoting/jingle_glue/fake_signal_strategy.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/logging.h" #include "base/message_loop.h" +#include "base/stl_util-inl.h" #include "base/string_number_conversions.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" #include "third_party/libjingle/source/talk/xmpp/constants.h" @@ -30,6 +31,10 @@ FakeSignalStrategy::FakeSignalStrategy(const std::string& jid) } FakeSignalStrategy::~FakeSignalStrategy() { + while (!pending_messages_.empty()) { + delete pending_messages_.front(); + pending_messages_.pop(); + } } void FakeSignalStrategy::Init(StatusObserver* observer) { @@ -77,25 +82,30 @@ IqRequest* FakeSignalStrategy::CreateIqRequest() { } void FakeSignalStrategy::OnIncomingMessage(buzz::XmlElement* stanza) { - MessageLoop::current()->PostTask( - FROM_HERE, task_factory_.NewRunnableMethod( - &FakeSignalStrategy::DeliverIncomingMessage, stanza)); + pending_messages_.push(stanza); + MessageLoop::current()->PostTask( + FROM_HERE, task_factory_.NewRunnableMethod( + &FakeSignalStrategy::DeliverIncomingMessages)); } -void FakeSignalStrategy::DeliverIncomingMessage(buzz::XmlElement* stanza) { - const std::string& to_field = stanza->Attr(buzz::QN_TO); - if (to_field != jid_) { - LOG(WARNING) << "Dropping stanza that is addressed to " << to_field - << ". Local jid: " << jid_ - << ". Message content: " << stanza->Str(); - return; +void FakeSignalStrategy::DeliverIncomingMessages() { + while (!pending_messages_.empty()) { + buzz::XmlElement* stanza = pending_messages_.front(); + const std::string& to_field = stanza->Attr(buzz::QN_TO); + if (to_field != jid_) { + LOG(WARNING) << "Dropping stanza that is addressed to " << to_field + << ". Local jid: " << jid_ + << ". Message content: " << stanza->Str(); + return; + } + + if (listener_) + listener_->OnIncomingStanza(stanza); + iq_registry_.OnIncomingStanza(stanza); + + pending_messages_.pop(); + delete stanza; } - - if (listener_) - listener_->OnIncomingStanza(stanza); - iq_registry_.OnIncomingStanza(stanza); - - delete stanza; } } // namespace remoting diff --git a/remoting/jingle_glue/fake_signal_strategy.h b/remoting/jingle_glue/fake_signal_strategy.h index 83e1ae9..553313e 100644 --- a/remoting/jingle_glue/fake_signal_strategy.h +++ b/remoting/jingle_glue/fake_signal_strategy.h @@ -5,6 +5,7 @@ #ifndef REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_ #define REMOTING_JINGLE_GLUE_FAKE_SIGNAL_STRATEGY_H_ +#include <queue> #include <string> #include "base/task.h" @@ -34,7 +35,7 @@ class FakeSignalStrategy : public SignalStrategy, // Called by the |peer_|. Takes ownership of |stanza|. void OnIncomingMessage(buzz::XmlElement* stanza); - void DeliverIncomingMessage(buzz::XmlElement* stanza); + void DeliverIncomingMessages(); std::string jid_; FakeSignalStrategy* peer_; @@ -43,6 +44,8 @@ class FakeSignalStrategy : public SignalStrategy, int last_id_; + std::queue<buzz::XmlElement*> pending_messages_; + ScopedRunnableMethodFactory<FakeSignalStrategy> task_factory_; DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy); |