Permalink
Browse files

Fix various memory access violations and double frees

  • Loading branch information...
1 parent f291f41 commit c114bc8225c8393592bf08db20bb147358ffe3d7 ec429 committed May 22, 2012
Showing with 26 additions and 3 deletions.
  1. +1 −1 buffer.c
  2. +1 −1 irc.c
  3. +22 −0 names.c
  4. +1 −0 names.h
  5. +1 −1 quirc.c
View
@@ -1019,7 +1019,7 @@ void titlebar(void)
locate(1, 1);
setcol(0, 7, true, false);
clr();
- unsigned int gits;
+ unsigned int gits=0;
sscanf(VERSION_TXT, "%u", &gits);
const char *hashgit=strchr(VERSION_TXT, ' ');
if(hashgit)
View
2 irc.c
@@ -184,7 +184,7 @@ int autoconnect(fd_set *master, int *fdmax, servlist *serv) // XXX broken in the
bufs[cbuf].handle=serverhandle;
bufs[cbuf].nick=strdup(serv->nick);
bufs[cbuf].autoent=serv;
- if(serv) bufs[cbuf].ilist=serv->igns;
+ if(serv) bufs[cbuf].ilist=n_dup(serv->igns);
bufs[cbuf].server=cbuf;
bufs[cbuf].conninpr=true;
add_to_buffer(cbuf, STA, QUIET, 0, false, cstr, "auto: ");
View
22 names.c
@@ -8,6 +8,28 @@
#include "names.h"
+name *n_dup(const name *list)
+{
+ if(!list) return(NULL);
+ name *rv=malloc(sizeof(name));
+ if(!rv) return(NULL);
+ *rv=*list;
+ rv->prev=NULL;
+ name *next=rv->next=n_dup(list->next);
+ if(next)
+ next->prev=rv;
+ rv->data=strdup(list->data);
+ rv->prefixes=malloc(rv->npfx*sizeof(prefix));
+ if(rv->prefixes)
+ {
+ for(unsigned int i=0;i<rv->npfx;i++)
+ rv->prefixes[i]=list->prefixes[i];
+ }
+ else
+ rv->npfx=0;
+ return(rv);
+}
+
name * n_add(name ** list, const char *data, cmap casemapping)
{
if(!list)
View
@@ -36,6 +36,7 @@ name;
#include "buffer.h"
#include "irc.h"
+name *n_dup(const name *list);
name * n_add(name ** list, const char *data, cmap casemapping); // returns pointer to the added name. Calls n_cull() first
int n_cull(name ** list, const char *data, cmap casemapping); // returns number of instances culled
void n_free(name * list);
View
@@ -247,7 +247,7 @@ int main(int argc, char *argv[])
{
free(bufs[cbuf].nick);
bufs[cbuf].nick=strdup(list->autoent->nick);
- bufs[cbuf].ilist=list->autoent->igns;
+ bufs[cbuf].ilist=n_dup(list->autoent->igns);
bufs[cbuf].autoent=list->autoent;
}
add_to_buffer(cbuf, STA, QUIET, 0, false, dstr, "/server: ");

0 comments on commit c114bc8

Please sign in to comment.