From b23819a4d17b5ec083e47a2e0f659bc7fb9980b3 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 23 Oct 2015 09:59:21 -0400 Subject: [PATCH] Fixed some memory related bugs. --- toxav/msi.c | 2 +- toxav/toxav.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/toxav/msi.c b/toxav/msi.c index ef307bcb..7ad39a54 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -528,7 +528,7 @@ MSICall *new_call (MSISession *session, uint32_t friend_number) session->calls_tail = session->calls_head = friend_number; } else if (session->calls_tail < friend_number) { /* Appending */ - void *tmp = realloc(session->calls, sizeof(MSICall *) * friend_number + 1); + void *tmp = realloc(session->calls, sizeof(MSICall *) * (friend_number + 1)); if (tmp == NULL) { free(rc); diff --git a/toxav/toxav.c b/toxav/toxav.c index a9e8b6f1..ab73ab4e 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -445,6 +445,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co goto END; } + call->msi_call = NULL; /* No mather the case, terminate the call */ call_kill_transmission(call); call_remove(call); @@ -1037,8 +1038,8 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error) av->calls_tail = av->calls_head = friend_number; - } else if (av->calls_tail < friend_number) { /* Appending */ - void *tmp = realloc(av->calls, sizeof(ToxAVCall *) * friend_number + 1); + } else if (av->calls_tail <= friend_number) { /* Appending */ + void *tmp = realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1)); if (tmp == NULL) { free(call); @@ -1097,7 +1098,10 @@ ToxAVCall *call_remove(ToxAVCall *call) /* Set av call in msi to NULL in order to know if call if ToxAVCall is * removed from the msi call. */ - call->msi_call->av_call = NULL; + if (call->msi_call) { + call->msi_call->av_call = NULL; + } + free(call); if (prev)