Fix a few initialisation problems and memleaks

This commit is contained in:
Alex Denes 2021-02-15 16:10:31 +00:00
parent 1979f7aa77
commit 36e0ebda0c
No account linked to committer's email address
3 changed files with 19 additions and 6 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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) {