summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/channels.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/channels.c b/src/channels.c
index 5ed5758c8..8191eccd3 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -1101,7 +1101,7 @@ void do_cmode(const char *source, int ac, char **av)
{
Channel *chan;
ChannelInfo *ci = NULL;
- int i;
+ int i, tofree0 = 0, tofree1 = 0, tofree2 = 0;
char *t;
if (ircdcap->tsmode) {
@@ -1133,9 +1133,24 @@ void do_cmode(const char *source, int ac, char **av)
if (debug) {
alog("debug: Before TS6 swap: do_cmode() chan %s : mode %s : extra %s", av[1], av[2], av[3]);
}
- av[0] = (ac >= 2 ? sstrdup(av[1]) : NULL);
- av[1] = (ac >= 3 ? sstrdup(av[2]) : NULL);
- av[2] = (ac >= 4 ? sstrdup(av[3]) : NULL);
+ if (ac >= 2) {
+ av[0] = sstrdup(av[1]);
+ tofree0 = 1;
+ } else {
+ av[0] = NULL;
+ }
+ if (ac >= 3) {
+ av[1] = sstrdup(av[2]);
+ tofree1 = 1;
+ } else {
+ av[1] = NULL;
+ }
+ if (ac >= 4) {
+ av[2] = sstrdup(av[3]);
+ tofree2 = 1;
+ } else {
+ av[2] = NULL;
+ }
if (debug) {
alog("debug: After TS swap: do_cmode() chan %s : mode %s : extra %s", av[0], av[1], av[2]);
}
@@ -1154,6 +1169,12 @@ void do_cmode(const char *source, int ac, char **av)
alog("debug: MODE %s for nonexistent channel %s",
merge_args(ac - 1, av + 1), av[0]);
}
+ if (tofree0)
+ free(av[0];
+ if (tofree1)
+ free(av[1];
+ if (tofree2)
+ free(av[2];
return;
}
@@ -1169,6 +1190,12 @@ void do_cmode(const char *source, int ac, char **av)
ac--;
av++;
chan_set_modes(source, chan, ac, av, 1);
+ if (tofree1)
+ free(av[0];
+ if (tofree2)
+ free(av[1];
+ if (tofree3)
+ free(av[2];
}
/*************************************************************************/