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));
|
IRC_Message* m = malloc(sizeof(IRC_Message));
|
||||||
char* const ws = malloc_string(str, strlen(str));
|
char* const ws = malloc_string(str, strlen(str));
|
||||||
char* p = ws;
|
char* p = ws;
|
||||||
|
|
||||||
if (ws == NULL || m == NULL) {
|
if (ws == NULL || m == NULL) {
|
||||||
free(ws);
|
free(ws);
|
||||||
free(m);
|
free(m);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(m, 0, sizeof(IRC_Message));
|
memset(m, 0, sizeof(IRC_Message));
|
||||||
strcpy(ws, str);
|
|
||||||
|
|
||||||
#ifdef UIRC_FEATURE_IRCV3
|
#ifdef UIRC_FEATURE_IRCV3
|
||||||
if (*p == '@') {
|
if (*p == '@') {
|
||||||
|
@ -74,8 +75,10 @@ uirc_tokenizer_message(const char* str)
|
||||||
free_ctx(m, ws);
|
free_ctx(m, ws);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
|
free_ctx(m, ws);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
skip_spaces(&p);
|
skip_spaces(&p);
|
||||||
|
|
||||||
short i;
|
short i;
|
||||||
|
|
|
@ -55,6 +55,7 @@ uirc_tokenizer_tag_list(const char* str)
|
||||||
connect_linked_list_elem(pl, cl);
|
connect_linked_list_elem(pl, cl);
|
||||||
pl = cl;
|
pl = cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ws);
|
free(ws);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
@ -69,9 +70,13 @@ uirc_tokenizer_tag(const char* str)
|
||||||
char* ckey = ws;
|
char* ckey = ws;
|
||||||
|
|
||||||
if (t == NULL || ws == NULL) {
|
if (t == NULL || ws == NULL) {
|
||||||
free_ctx(NULL, t, ws);
|
free(t);
|
||||||
|
free(ws);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(t, 0, sizeof(IRC_Tag));
|
||||||
|
|
||||||
if (*ws == '+') {
|
if (*ws == '+') {
|
||||||
ckey++;
|
ckey++;
|
||||||
t->clientbound = true;
|
t->clientbound = true;
|
||||||
|
@ -88,6 +93,7 @@ uirc_tokenizer_tag(const char* str)
|
||||||
free_ctx(NULL, t, ws);
|
free_ctx(NULL, t, ws);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ws);
|
free(ws);
|
||||||
return t;
|
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);
|
if (l->content != NULL) uirc_free_tag(l->content);
|
||||||
remove_linked_list_elem(l);
|
remove_linked_list_elem(l);
|
||||||
}
|
}
|
||||||
|
uirc_free_tag(t);
|
||||||
free(t);
|
free(t);
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,19 +29,22 @@
|
||||||
static void free_ctx(IRC_User* u, char* s);
|
static void free_ctx(IRC_User* u, char* s);
|
||||||
|
|
||||||
IRC_User*
|
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));
|
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;
|
char* tmp;
|
||||||
|
|
||||||
if (u == NULL || ws == NULL) {
|
if (u == NULL || ws == NULL) {
|
||||||
free(u);
|
free(u);
|
||||||
free(ws);
|
free(ws);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(u, 0, sizeof(IRC_User));
|
||||||
|
|
||||||
if ((tmp = strchr(ws, '@')) != NULL) {
|
if ((tmp = strchr(ws, '@')) != NULL) {
|
||||||
*(tmp++) = '\0';
|
*(tmp++) = '\0';
|
||||||
if ((u->host = malloc_string(tmp, strlen(tmp))) == NULL) {
|
if ((u->host = malloc_string(tmp, strlen(tmp))) == NULL) {
|
||||||
|
|
Reference in New Issue