mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:43:02 +01:00
Fix two memory leaks and properly clean up friendlist window
This commit is contained in:
parent
ce6d4861fb
commit
d18cc8cbc2
@ -113,11 +113,9 @@ static void realloc_blocklist(int n)
|
||||
Blocked.index = b_idx;
|
||||
}
|
||||
|
||||
void kill_friendlist(void)
|
||||
void kill_friendlist(ToxWindow *self)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < Friends.max_idx; ++i) {
|
||||
for (int i = 0; i < Friends.max_idx; ++i) {
|
||||
if (Friends.list[i].active && Friends.list[i].group_invite.key != NULL) {
|
||||
free(Friends.list[i].group_invite.key);
|
||||
}
|
||||
@ -125,6 +123,8 @@ void kill_friendlist(void)
|
||||
|
||||
realloc_blocklist(0);
|
||||
realloc_friends(0);
|
||||
free(self->help);
|
||||
del_window(self);
|
||||
}
|
||||
|
||||
/* Saves the blocklist to path. If there are no items in the blocklist the
|
||||
|
@ -85,7 +85,7 @@ ToxWindow new_friendlist(void);
|
||||
void disable_chatwin(uint32_t f_num);
|
||||
int get_friendnum(uint8_t *name);
|
||||
int load_blocklist(char *data);
|
||||
void kill_friendlist(void);
|
||||
void kill_friendlist(ToxWindow *self);
|
||||
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, uint32_t num, bool sort);
|
||||
Tox_User_Status get_friend_status(uint32_t friendnumber);
|
||||
Tox_Connection get_friend_connection_status(uint32_t friendnumber);
|
||||
|
@ -113,6 +113,21 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
#endif /* PYTHON */
|
||||
};
|
||||
|
||||
static void kill_groupchat_window(ToxWindow *self)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
log_disable(ctx->log);
|
||||
line_info_cleanup(ctx->hst);
|
||||
delwin(ctx->linewin);
|
||||
delwin(ctx->history);
|
||||
delwin(ctx->sidebar);
|
||||
free(ctx->log);
|
||||
free(ctx);
|
||||
free(self->help);
|
||||
del_window(self);
|
||||
}
|
||||
|
||||
int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t type)
|
||||
{
|
||||
if (groupnum > MAX_GROUPCHAT_NUM) {
|
||||
@ -120,9 +135,8 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t typ
|
||||
}
|
||||
|
||||
ToxWindow self = new_group_chat(m, groupnum);
|
||||
int i;
|
||||
|
||||
for (i = 0; i <= max_groupchat_index; ++i) {
|
||||
for (int i = 0; i <= max_groupchat_index; ++i) {
|
||||
if (!groupchats[i].active) {
|
||||
groupchats[i].chatwin = add_window(m, self);
|
||||
groupchats[i].active = true;
|
||||
@ -140,24 +154,11 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t typ
|
||||
}
|
||||
}
|
||||
|
||||
kill_groupchat_window(&self);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void kill_groupchat_window(ToxWindow *self)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
log_disable(ctx->log);
|
||||
line_info_cleanup(ctx->hst);
|
||||
delwin(ctx->linewin);
|
||||
delwin(ctx->history);
|
||||
delwin(ctx->sidebar);
|
||||
free(ctx->log);
|
||||
free(ctx);
|
||||
free(self->help);
|
||||
del_window(self);
|
||||
}
|
||||
|
||||
void free_groupchat(ToxWindow *self, Tox *m, uint32_t groupnum)
|
||||
{
|
||||
free(groupchats[groupnum].name_list);
|
||||
|
@ -667,7 +667,7 @@ void kill_all_windows(Tox *m)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
for (i = 2; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].is_chat) {
|
||||
kill_chat_window(&windows[i], m);
|
||||
} else if (windows[i].is_groupchat) {
|
||||
@ -675,6 +675,7 @@ void kill_all_windows(Tox *m)
|
||||
}
|
||||
}
|
||||
|
||||
kill_prompt_window(prompt);
|
||||
kill_friendlist();
|
||||
/* TODO: use enum instead of magic indices */
|
||||
kill_friendlist(&windows[1]);
|
||||
kill_prompt_window(&windows[0]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user