Permalink
Browse files

Fix issue (#18) with double-free(nick)

Now the canonical 'default nick' is bufs[0].nick, which is derived from nick.
As soon as bufs[0].nick is set, nick is NULLed.  This should winkle out any
 uses that I've missed.
  • Loading branch information...
1 parent 0da630e commit 4a6824e22c3eb4176d1147bb4a6a6999b2cf1475 @ec429 committed Dec 18, 2012
Showing with 5 additions and 6 deletions.
  1. +1 −0 buffer.c
  2. +1 −3 input.c
  3. +3 −3 quirc.c
View
@@ -99,6 +99,7 @@ int initialise_buffers(int buflines)
cbuf=0;
bufs[0].live=true; // STATUS is never dead
bufs[0].nick=nick;
+ nick=NULL;
bufs[0].ilist=igns;
add_to_buffer(0, STA, QUIET, 0, false, GPL_TAIL, "quirc -- ");
init_ring(&d_buf);
View
@@ -811,7 +811,7 @@ int cmd_handle(char *inp, char **qmsg, fd_set *master, int *fdmax) // old state=
init_buffer(nbufs-1, SERVER, server, buflines);
cbuf=nbufs-1;
bufs[cbuf].handle=serverhandle;
- bufs[cbuf].nick=strdup(nick);
+ bufs[cbuf].nick=bufs[0].nick?strdup(bufs[0].nick):NULL;
bufs[cbuf].server=cbuf;
bufs[cbuf].conninpr=true;
add_to_buffer(cbuf, STA, QUIET, 0, false, dstr, "/server: ");
@@ -1159,8 +1159,6 @@ int cmd_handle(char *inp, char **qmsg, fd_set *master, int *fdmax) // old state=
{
free(bufs[0].nick);
bufs[0].nick=strdup(nn);
- free(nick);
- nick=strdup(nn);
defnick=false;
add_to_buffer(cbuf, STA, QUIET, 0, false, "Default nick changed", "/nick: ");
}
View
@@ -253,7 +253,7 @@ int main(int argc, char *argv[])
init_buffer(nbufs-1, SERVER, server, buflines);
cbuf=nbufs-1;
bufs[cbuf].handle=serverhandle;
- bufs[cbuf].nick=strdup(nick);
+ bufs[cbuf].nick=bufs[0].nick?strdup(bufs[0].nick):NULL;
bufs[cbuf].server=cbuf;
bufs[cbuf].conninpr=true;
if(list->autoent)
@@ -475,7 +475,7 @@ int main(int argc, char *argv[])
}
else if(bufs[b].conninpr)
{
- irc_conn_rest(b, nick, username, pass, fname);
+ irc_conn_rest(b, bufs[0].nick, username, pass, fname);
}
else
{
@@ -570,7 +570,7 @@ int main(int argc, char *argv[])
free(username);
free(fname);
free(qmsg);
- free(nick);
+ free(nick); // should be NULL by now anyway
free(portno);
freeservlist(servs);
n_free(igns);

0 comments on commit 4a6824e

Please sign in to comment.