From: Egor Date: Tue, 3 May 2022 08:15:40 +0000 (+0300) Subject: fix memory leaks X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=d4334f8153aaecc6fe63a50a8944975f0eab645e;p=patchyircd.git fix memory leaks --- diff --git a/irc.c b/irc.c index 78037fe..95f6f8b 100644 --- a/irc.c +++ b/irc.c @@ -281,8 +281,8 @@ void setNick(struct client_data *client, char* nickname) { return; } - char *key = mystrdup(nickname); - if (!key) abort(); + char key[MAX_NICKLEN]; + strcpy(key, nickname); stringlower(key); if (trie_get(&client_map, key)) { @@ -300,12 +300,16 @@ void setNick(struct client_data *client, char* nickname) { sendall_log(client->FD, databuf.buf, databuf.len, 0); trie_set(&client_map, client->key, NULL, NULL); free(client->nick); + free(client->key); } client->nick = mystrdup(nickname); if (!client->nick) abort(); - if (trie_set(&client_map, client->key = key, client, 0) == -1) + client->key = mystrdup(key); + if (!client->key) + abort(); + if (trie_set(&client_map, client->key, client, 0) == -1) abort(); return; diff --git a/main.c b/main.c index 4dd5c04..659d6ec 100644 --- a/main.c +++ b/main.c @@ -296,5 +296,6 @@ int main() { } } net_cleanup(); + free(databuf.buf); return 0; }