Skip to content

Commit

Permalink
Fix group av memory leak
Browse files Browse the repository at this point in the history
Introduced in 762a601
  • Loading branch information
JFreegman committed Jan 22, 2022
1 parent 10d59d6 commit cba1b98
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions toxav/groupav.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ typedef struct Group_JitterBuffer {
uint64_t last_queued_time;
} Group_JitterBuffer;

static void free_audio_packet(Group_Audio_Packet *pk)
{
if (pk == nullptr) {
return;
}

free(pk->data);
free(pk);
}

static Group_JitterBuffer *create_queue(unsigned int capacity)
{
unsigned int size = 1;
Expand Down Expand Up @@ -58,11 +68,9 @@ static Group_JitterBuffer *create_queue(unsigned int capacity)
static void clear_queue(Group_JitterBuffer *q)
{
while (q->bottom != q->top) {
if (q->queue[q->bottom % q->size]) {
free(q->queue[q->bottom % q->size]);
q->queue[q->bottom % q->size] = nullptr;
}

const size_t idx = q->bottom % q->size;
free_audio_packet(q->queue[idx]);
q->queue[idx] = nullptr;
++q->bottom;
}
}
Expand Down Expand Up @@ -279,16 +287,6 @@ static void group_av_groupchat_delete(void *object, uint32_t groupnumber)
}
}

static void free_audio_packet(Group_Audio_Packet *pk)
{
if (pk == nullptr) {
return;
}

free(pk->data);
free(pk);
}

static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint32_t groupnumber,
uint32_t friendgroupnumber)
{
Expand Down

0 comments on commit cba1b98

Please sign in to comment.