soc.2009.transport: 1ab691af: Fixed memleaks with stanza.tag()
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Mon Jun 22 14:45:40 EDT 2009
-----------------------------------------------------------------
Revision: 1ab691af036fed0ccf287475afb4f53191a5dd16
Ancestor: f84a9283b4fac94933611d751b3c314c422577f1
Author: hanzz at soc.pidgin.im
Date: 2009-06-22T18:42:25
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/1ab691af036fed0ccf287475afb4f53191a5dd16
Modified files:
adhochandler.cpp adhocrepeater.cpp adhocsettings.cpp
caps.cpp discoinfohandler.cpp gatewayhandler.cpp main.cpp
registerhandler.cpp statshandler.cpp
ChangeLog:
Fixed memleaks with stanza.tag()
-------------- next part --------------
============================================================
--- adhochandler.cpp 6e7e9462e60bb7b4f257741160f9993d744ede5a
+++ adhochandler.cpp 4540027637a1a7d64faaa9ec04e0098b26765d9b
@@ -124,9 +124,14 @@ bool GlooxAdhocHandler::handleIq( const
Log().Get("GlooxAdhocHandler") << "handleIq";
std::string to = stanza.to().bare();
std::string from = stanza.from().bare();
- Tag *tag = stanza.tag()->findChild( "command" );
+ Tag *stanzaTag = stanza.tag();
+ if (!stanzaTag) return false;
+ Tag *tag = stanzaTag->findChild( "command" );
const std::string& node = tag->findAttribute( "node" );
- if (node.empty()) return false;
+ if (node.empty()) {
+ delete stanzaTag;
+ return false;
+ }
User *user = main->userManager()->getUserByJID(from);
if (user) {
@@ -136,11 +141,13 @@ bool GlooxAdhocHandler::handleIq( const
delete m_sessions[jid];
unregisterSession(jid);
}
+ delete stanzaTag;
return true;
}
else if (m_handlers.find(node) != m_handlers.end()) {
AdhocCommandHandler *handler = m_handlers[node].createHandler(main, user, stanza.from().full(), stanza.id());
registerSession(stanza.from().full(), handler);
+ delete stanzaTag;
return true;
}
if (user->isConnected() && purple_account_get_connection(user->account())) {
@@ -208,6 +215,7 @@ bool GlooxAdhocHandler::handleIq( const
}
}
}
+ delete stanzaTag;
return true;
}
============================================================
--- adhocrepeater.cpp de702e24353f8b93dc682cdbfd08817721c072d5
+++ adhocrepeater.cpp 32579e7a71c4f4bba6f3c2bffd7ee33502889529
@@ -145,7 +145,9 @@ bool AdhocRepeater::handleIq(const IQ &s
AdhocRepeater::~AdhocRepeater() {}
bool AdhocRepeater::handleIq(const IQ &stanza) {
- Tag *tag = stanza.tag()->findChild( "command" );
+ Tag *stanzaTag = stanza.tag();
+ if (!stanzaTag) return false;
+ Tag *tag = stanzaTag->findChild( "command" );
if (tag->hasAttribute("action","cancel")){
IQ _response(IQ::Result, stanza.from().full(), stanza.id());
_response.setFrom(main->jid());
@@ -160,7 +162,7 @@ bool AdhocRepeater::handleIq(const IQ &s
main->j->send(response);
g_timeout_add(0,&removeRepeater,this);
-
+ delete stanzaTag;
return false;
}
@@ -204,7 +206,7 @@ bool AdhocRepeater::handleIq(const IQ &s
}
-
+ delete stanzaTag;
return false;
}
============================================================
--- adhocsettings.cpp fa29a91eabf7daf6c0a2dd5a9b55c1c1bdc12e84
+++ adhocsettings.cpp 5eb4f8ad9a7dc72bf4828c5e708cfc53ae41c49f
@@ -103,7 +103,8 @@ bool AdhocSettings::handleIq(const IQ &s
AdhocSettings::~AdhocSettings() {}
bool AdhocSettings::handleIq(const IQ &stanza) {
- Tag *tag = stanza.tag()->findChild( "command" );
+ Tag *stanzaTag = stanza.tag();
+ Tag *tag = stanzaTag->findChild( "command" );
if (tag->hasAttribute("action","cancel")){
IQ _response(IQ::Result, stanza.from().full(), stanza.id());
_response.setFrom(main->jid());
@@ -118,7 +119,7 @@ bool AdhocSettings::handleIq(const IQ &s
main->j->send(response);
// g_timeout_add(0,&removeHandler,this);
-
+ delete stanzaTag;
return true;
}
@@ -159,11 +160,10 @@ bool AdhocSettings::handleIq(const IQ &s
s->addChild(c);
main->j->send(s);
-// g_timeout_add(0,&removeRepeater,this);
-
+// g_timeout_add(0,&removeRepeater,this);
}
-
+ delete stanzaTag;
return true;
}
============================================================
--- caps.cpp 5a849ea713156c015883216cd37c1a935fb04e9a
+++ caps.cpp c04a1bc5d73e0f91b21d5604d2a6ecd6f5831952
@@ -56,8 +56,10 @@ void GlooxDiscoHandler::handleDiscoInfo(
//if (query->findChild("identity") && query->findChild("identity")->findChild("category") && !query->findChild("identity")->findChildWithAttrib("category","client"))
//return;
Tag *query = info.tag();
- if (query->findChild("identity") && !query->findChildWithAttrib("category","client"))
+ if (query->findChild("identity") && !query->findChildWithAttrib("category","client")) {
+ delete query;
return;
+ }
int feature=0;
std::list<Tag*> features = query->findChildren("feature");
for (std::list<Tag*>::const_iterator it = features.begin(); it != features.end(); ++it) {
@@ -94,6 +96,7 @@ void GlooxDiscoHandler::handleDiscoInfo(
}
// TODO: CACHE CAPS IN DATABASE ACCORDING TO VERSION
versions.erase(context);
+ delete query;
}
void GlooxDiscoHandler::handleDiscoItems(const JID &jid, const Disco::Items &items, int context){
============================================================
--- discoinfohandler.cpp 9b15b6bda717ad0504c444bae027a703b4819797
+++ discoinfohandler.cpp d90361f0007fb05d2fb8e4f1736adf52fe295f25
@@ -60,7 +60,9 @@ bool GlooxDiscoInfoHandler::handleIq (co
std::cout << "DISCO DISCO DISCO INFO\n";
if(stanza.subtype() == IQ::Get && stanza.to().username()!="") {
- Tag *query = stanza.tag()->findChildWithAttrib("xmlns","http://jabber.org/protocol/disco#info");
+ Tag *stanzaTag = stanza.tag();
+ if (!stanzaTag) return true;
+ Tag *query = stanzaTag->findChildWithAttrib("xmlns","http://jabber.org/protocol/disco#info");
if (query!=NULL){
IQ _s(IQ::Result, stanza.from(), stanza.id());
_s.setFrom(stanza.to().full());
@@ -86,6 +88,7 @@ bool GlooxDiscoInfoHandler::handleIq (co
s->addChild(query2);
p->j->send( s );
+ delete stanzaTag;
return true;
}
}
============================================================
--- gatewayhandler.cpp d63322f0bfb56e04958638dfb2345346b35558dd
+++ gatewayhandler.cpp c4afbe9f7c4d9da446de50d1480b9fa28597735e
@@ -99,8 +99,9 @@ bool GlooxGatewayHandler::handleIq (cons
return true;
}
else if(stanza.subtype() == IQ::Set){
- Log().Get("tag") << stanza.tag()->xml();
- Tag *query = stanza.tag()->findChild("query");
+ Tag *stanzaTag = stanza.tag();
+ Log().Get("tag") << stanzaTag->xml();
+ Tag *query = stanzaTag->findChild("query");
if (query==NULL)
return false;
Tag *prompt = query->findChild("prompt");
@@ -124,6 +125,7 @@ bool GlooxGatewayHandler::handleIq (cons
s->addChild(query);
p->j->send( s );
+ delete stanzaTag;
return true;
}
============================================================
--- main.cpp 2d63b68c17096377bd6d7ddf0d081c48f39fced2
+++ main.cpp 6e913f09e3b6250d6f318eb8c25df021c8e5aeee
@@ -1097,7 +1097,9 @@ void GlooxMessageHandler::handlePresence
Log().Get(stanza.from().full()) << "Presence received (" << stanza.subtype() << ") for: " << stanza.to().full();
if (stanza.presence() != Presence::Unavailable && stanza.to().username() == ""){
- Tag *c = stanza.tag()->findChildWithAttrib("xmlns","http://jabber.org/protocol/caps");
+ Tag *stanzaTag = stanza.tag();
+ if (!stanzaTag) return;
+ Tag *c = stanzaTag->findChildWithAttrib("xmlns","http://jabber.org/protocol/caps");
// presence has caps
if (c!=NULL){
// caps is not chached
@@ -1126,6 +1128,7 @@ void GlooxMessageHandler::handlePresence
j->disco()->getDiscoInfo(stanza.from(),"",m_discoHandler,m_discoHandler->version,id);
m_discoHandler->version++;
}
+ delete stanzaTag;
}
User *user = userManager()->getUserByJID(stanza.from().bare());
@@ -1242,17 +1245,19 @@ void GlooxMessageHandler::handleMessage
User *user = userManager()->getUserByJID(msg.from().bare());
if (user!=NULL){
if (user->isConnected()){
- Tag *chatstates = msg.tag()->findChildWithAttrib("xmlns","http://jabber.org/protocol/chatstates");
+ Tag *msgTag = msg.tag();
+ if (!msgTag) return;
+ Tag *chatstates = msgTag->findChildWithAttrib("xmlns","http://jabber.org/protocol/chatstates");
if (chatstates!=NULL){
user->receivedChatState(msg.to().username(),chatstates->name());
}
- if(msg.tag()->findChild("body")!=NULL) {
+ if(msgTag->findChild("body")!=NULL) {
m_stats->messageFromJabber();
user->receivedMessage(msg);
}
else {
// handle activity; TODO: move me to another function or better file
- Tag *event = msg.tag()->findChild("event");
+ Tag *event = msgTag->findChild("event");
if (!event) return;
Tag *items = event->findChildWithAttrib("node","http://jabber.org/protocol/activity");
if (!items) return;
@@ -1290,6 +1295,7 @@ void GlooxMessageHandler::handleMessage
}
}
}
+ delete msgTag;
}
else{
Log().Get(msg.from().bare()) << "New message received, but we're not connected yet";
============================================================
--- registerhandler.cpp fe4c2e088e394f1f05c15fb2adb733482ce8cebf
+++ registerhandler.cpp f6a7b0df0b1b1220a76739f04d57e4555584ab6e
@@ -87,7 +87,8 @@ bool GlooxRegisterHandler::handleIq (con
}
else if(iq.subtype() == IQ::Set) {
bool sendsubscribe = false;
- Tag *query = iq.tag()->findChild( "query" );
+ Tag *iqTag = iq.tag();
+ Tag *query = iqTag->findChild( "query" );
if (!query) return true;
@@ -164,6 +165,8 @@ bool GlooxRegisterHandler::handleIq (con
reply->addAttribute( "to", iq.from().full() );
reply->addAttribute( "from", p->jid() );
p->j->send( reply );
+
+ delete iqTag;
return true;
}
@@ -218,6 +221,7 @@ bool GlooxRegisterHandler::handleIq (con
p->j->send(iq2);
+ delete iqTag;
return true;
}
@@ -259,12 +263,13 @@ bool GlooxRegisterHandler::handleIq (con
p->j->send( reply );
if(sendsubscribe) {
- reply = new Tag("presence");
- reply->addAttribute( "from", p->jid() );
- reply->addAttribute( "to", iq.from().bare() );
- reply->addAttribute( "type", "subscribe" );
- p->j->send( reply );
+ reply = new Tag("presence");
+ reply->addAttribute( "from", p->jid() );
+ reply->addAttribute( "to", iq.from().bare() );
+ reply->addAttribute( "type", "subscribe" );
+ p->j->send( reply );
}
+ delete iqTag;
return true;
}
return false;
============================================================
--- statshandler.cpp 5a58faba0a755da41c14bc4f2872fc70ffe42b0c
+++ statshandler.cpp 8c90bb62f61eec8e23008d23caa0932db6f8e6ff
@@ -80,9 +80,12 @@ bool GlooxStatsHandler::handleIq (const
// </iq>
//
- Tag *query = stanza.tag()->findChild("query");
- if (query==NULL)
+ Tag *stanzaTag = stanza.tag();
+ Tag *query = stanzaTag->findChild("query");
+ if (query==NULL) {
+ delete stanzaTag;
return true;
+ }
std::cout << "*** "<< stanza.from().full() << ": received stats request\n";
std::list<Tag*> stats = query->children();
if (stats.empty()){
@@ -201,6 +204,7 @@ bool GlooxStatsHandler::handleIq (const
}
+ delete stanzaTag;
return true;
}
More information about the Commits
mailing list