Skip to content

Commit fde2a7d

Browse files
committed
fix: properly deallocate frozen peers
1 parent 84a03bc commit fde2a7d

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

toxcore/group.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ static int32_t create_group_chat(Group_Chats *g_c)
131131
return -1;
132132
}
133133

134+
non_null()
135+
static void wipe_group_c(Group_c *g)
136+
{
137+
free(g->frozen);
138+
free(g->group);
139+
crypto_memzero(g, sizeof(Group_c));
140+
}
134141

135142
/** Wipe a groupchat.
136143
*
@@ -139,12 +146,13 @@ static int32_t create_group_chat(Group_Chats *g_c)
139146
non_null()
140147
static bool wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber)
141148
{
142-
if (!is_groupnumber_valid(g_c, groupnumber)) {
149+
if (groupnumber >= g_c->num_chats || g_c->chats == nullptr) {
143150
return false;
144151
}
145152

153+
wipe_group_c(&g_c->chats[groupnumber]);
154+
146155
uint16_t i;
147-
crypto_memzero(&g_c->chats[groupnumber], sizeof(Group_c));
148156

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

1211-
free(g->group);
1212-
free(g->frozen);
1213-
12141219
if (g->group_on_delete != nullptr) {
12151220
g->group_on_delete(g->object, groupnumber);
12161221
}

0 commit comments

Comments
 (0)