Skip to content

Commit

Permalink
fix: properly deallocate frozen peers
Browse files Browse the repository at this point in the history
  • Loading branch information
sudden6 committed Feb 18, 2022
1 parent 84a03bc commit fde2a7d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions toxcore/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ static int32_t create_group_chat(Group_Chats *g_c)
return -1;
}

non_null()
static void wipe_group_c(Group_c *g)
{
free(g->frozen);
free(g->group);
crypto_memzero(g, sizeof(Group_c));
}

/** Wipe a groupchat.
*
Expand All @@ -139,12 +146,13 @@ static int32_t create_group_chat(Group_Chats *g_c)
non_null()
static bool wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber)
{
if (!is_groupnumber_valid(g_c, groupnumber)) {
if (groupnumber >= g_c->num_chats || g_c->chats == nullptr) {
return false;
}

wipe_group_c(&g_c->chats[groupnumber]);

uint16_t i;
crypto_memzero(&g_c->chats[groupnumber], sizeof(Group_c));

for (i = g_c->num_chats; i != 0; --i) {
if (g_c->chats[i - 1].status != GROUPCHAT_STATUS_NONE) {
Expand Down Expand Up @@ -1208,9 +1216,6 @@ int del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanently
}
}

free(g->group);
free(g->frozen);

if (g->group_on_delete != nullptr) {
g->group_on_delete(g->object, groupnumber);
}
Expand Down

0 comments on commit fde2a7d

Please sign in to comment.