Fix overall memory bugs concerning modes and the oligosI plugin.

parent 8edc48af
......@@ -188,7 +188,7 @@ _EVENT(MODE) {
char *tgt;
char **targets = (char **)calloc(1, sizeof(char *));
while ((tgt = strsep(&msgbuf, " ")) != NULL) {
targets[tc++] = tgt;
targets[tc++] = strdup(tgt);
targets = (char **)realloc(targets, tc+1);
}
......@@ -218,6 +218,9 @@ _EVENT(MODE) {
c->giveMode((oligos_mode)(sign == '+' ? usr->modeInChannel(c) | im2om(mode) : usr->modeInChannel(c) & (~(im2om(mode)))), usr);
}
for (i=0; i<tc; i++) free(targets[i]);
free(targets);
}
}
......
......@@ -64,7 +64,7 @@ namespace YAML {
}
static bool decode(const Node &node, OligosChannel *&rhs) {
if (!node.IsMap() || node.size() != 2)
if (!node.IsMap() || (node.size() != 2 && node.size() != 3))
return false;
rhs = new OligosChannel;
......@@ -157,28 +157,21 @@ static char *ModeLineForUser(char *channel, char *user) {
return ret;
}
// Should pass result to free()
static char **ModeLinesForUsers(char *channel, unsigned int *length) {
static std::list<std::string> ModeLinesForUsers(char *channel) {
OligosChannel *channelNode;
if (!_ChannelNodeForString(channel, &channelNode)) return NULL;
if (!_ChannelNodeForString(channel, &channelNode)) return std::list<std::string>();
std::list<OligosUser *> people = channelNode->people;
char **ret = NULL;
int i = 0;
std::list<OligosUser *> &people = channelNode->people;
std::list<std::string> ret;
for (std::list<OligosUser *>::const_iterator it=people.begin(), end=people.end(); it != end; ++it) {
std::string userName = (*it)->name;
std::string modeString = (*it)->mode;
if (modeString[0] != '+' || modeString[0] != '-')
modeString.insert(modeString.begin(), '+');
ret = (char **)realloc(ret, i+1 * sizeof(char *));
char *str;
asprintf(&str, "MODE %s %s %s", channel, modeString.c_str(), userName.c_str());
ret[i++] = str;
ret.push_back(std::string("MODE ") + channel + " " + modeString + " " + userName);
}
*length = i;
return ret;
}
......@@ -272,16 +265,12 @@ static oligos_cmd_return_t parsecmd(server *server, const char *cmd, int argc, c
return OLIGOS_CMD_OK;
}
unsigned int length;
char **modelines = ModeLinesForUsers(state->channel, &length);
for (int i=0; i<length; i++) {
char *modeline = modelines[i];
server->printf("%s", modeline);
free(modeline);
std::list<std::string> modelines = ModeLinesForUsers(state->channel);
for (std::list<std::string>::const_iterator it=modelines.begin(), end=modelines.end(); it != end; ++it) {
std::string modeline = *it;
printf("and content = %s\n", modeline.c_str());
server->printf("%s", modeline.c_str());
}
free(modelines);
server->printf("PRIVMSG %s :Okay.", state->channel);
}
else
......
......@@ -261,6 +261,8 @@ user *server::user_(struct sender *person, bool create) {
_D("went past isircmode\n");
_D("person! %p %s\n", person, person->nick);
_D("will print info!\n");
_D("info about person: %s %s %s\n", person->nick, person->username, person->host);
user_find_predicate pred(person);
_D("predicate successfully initialized!\n");
user_set::iterator iterator = std::find_if(users.begin(), users.end(), pred);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment