Fix a few initialisation problems and memleaks
This commit is contained in:
parent
1979f7aa77
commit
36e0ebda0c
|
@ -38,13 +38,14 @@ uirc_tokenizer_message(const char* str)
|
|||
IRC_Message* m = malloc(sizeof(IRC_Message));
|
||||
char* const ws = malloc_string(str, strlen(str));
|
||||
char* p = ws;
|
||||
|
||||
if (ws == NULL || m == NULL) {
|
||||
free(ws);
|
||||
free(m);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(m, 0, sizeof(IRC_Message));
|
||||
strcpy(ws, str);
|
||||
|
||||
#ifdef UIRC_FEATURE_IRCV3
|
||||
if (*p == '@') {
|
||||
|
@ -74,8 +75,10 @@ uirc_tokenizer_message(const char* str)
|
|||
free_ctx(m, ws);
|
||||
return NULL;
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
free_ctx(m, ws);
|
||||
return NULL;
|
||||
}
|
||||
skip_spaces(&p);
|
||||
|
||||
short i;
|
||||
|
|
|
@ -55,6 +55,7 @@ uirc_tokenizer_tag_list(const char* str)
|
|||
connect_linked_list_elem(pl, cl);
|
||||
pl = cl;
|
||||
}
|
||||
|
||||
free(ws);
|
||||
return l;
|
||||
}
|
||||
|
@ -69,9 +70,13 @@ uirc_tokenizer_tag(const char* str)
|
|||
char* ckey = ws;
|
||||
|
||||
if (t == NULL || ws == NULL) {
|
||||
free_ctx(NULL, t, ws);
|
||||
free(t);
|
||||
free(ws);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(t, 0, sizeof(IRC_Tag));
|
||||
|
||||
if (*ws == '+') {
|
||||
ckey++;
|
||||
t->clientbound = true;
|
||||
|
@ -88,6 +93,7 @@ uirc_tokenizer_tag(const char* str)
|
|||
free_ctx(NULL, t, ws);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free(ws);
|
||||
return t;
|
||||
}
|
||||
|
@ -101,6 +107,7 @@ free_ctx(llist_t* list, IRC_Tag* t, char* s)
|
|||
if (l->content != NULL) uirc_free_tag(l->content);
|
||||
remove_linked_list_elem(l);
|
||||
}
|
||||
uirc_free_tag(t);
|
||||
free(t);
|
||||
free(s);
|
||||
}
|
||||
|
|
|
@ -29,19 +29,22 @@
|
|||
static void free_ctx(IRC_User* u, char* s);
|
||||
|
||||
IRC_User*
|
||||
uirc_tokenizer_user(const char* s)
|
||||
uirc_tokenizer_user(const char* str)
|
||||
{
|
||||
assert(s != NULL);
|
||||
assert(str != NULL);
|
||||
|
||||
IRC_User* u = malloc(sizeof(IRC_User));
|
||||
char* const ws = malloc_string(s, strlen(s));
|
||||
char* const ws = malloc_string(str, strlen(str));
|
||||
char* tmp;
|
||||
|
||||
if (u == NULL || ws == NULL) {
|
||||
free(u);
|
||||
free(ws);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(u, 0, sizeof(IRC_User));
|
||||
|
||||
if ((tmp = strchr(ws, '@')) != NULL) {
|
||||
*(tmp++) = '\0';
|
||||
if ((u->host = malloc_string(tmp, strlen(tmp))) == NULL) {
|
||||
|
|
Reference in New Issue