1
0
mirror of https://github.com/anope/anope.git synced 2026-07-07 07:33:13 +02:00

Defer channel deletion until after i/o. There are some edge cases with events kicking users mid-event that can delete them.

This commit is contained in:
Adam
2015-09-17 10:07:30 -04:00
parent 8d13a355cd
commit 1ac4a1d9a5
5 changed files with 26 additions and 14 deletions
+17 -5
View File
@@ -27,6 +27,7 @@
#include "uplink.h"
channel_map ChannelList;
std::vector<Channel *> Channel::deleting;
Channel::Channel(const Anope::string &nname, time_t ts)
{
@@ -168,8 +169,8 @@ void Channel::DeleteUser(User *user)
Log(LOG_DEBUG) << "Channel::DeleteUser() tried to delete non-existent channel " << this->name << " from " << user->nick << "'s channel list";
delete cu;
if (this->CheckDelete())
delete this;
if (std::find(deleting.begin(), deleting.end(), this) == deleting.end())
deleting.push_back(this);
}
ChanUserContainer *Channel::FindUser(User *u) const
@@ -759,12 +760,11 @@ void Channel::KickInternal(const MessageSource &source, const Anope::string &nic
return;
}
Anope::string this_name = this->name;
ChannelStatus status = cu->status;
FOREACH_MOD(OnPreUserKicked, (source, cu, reason));
this->DeleteUser(target); /* This can delete this; */
FOREACH_MOD(OnUserKicked, (source, target, this_name, status, reason));
this->DeleteUser(target);
FOREACH_MOD(OnUserKicked, (source, target, this->name, status, reason));
}
bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...)
@@ -939,3 +939,15 @@ Channel *Channel::FindOrCreate(const Anope::string &name, bool &created, time_t
return chan;
}
void Channel::DeleteChannels()
{
for (unsigned int i = 0; i < deleting.size(); ++i)
{
Channel *c = deleting[i];
if (c->CheckDelete())
delete c;
}
deleting.clear();
}