1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 22:03:27 +01:00

fix segfault and memory leak

This commit is contained in:
Jfreegman 2014-04-01 02:38:32 -04:00
parent 3b7e161149
commit 08f57de9e0
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 5 additions and 1 deletions

View File

@ -106,7 +106,6 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, uint8_t *
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
uint16_t n_len = tox_get_name(m, num, nick); uint16_t n_len = tox_get_name(m, num, nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH);
nick[n_len] = '\0'; nick[n_len] = '\0';
@ -217,6 +216,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
uint8_t nick[TOX_MAX_NAME_LENGTH]; uint8_t nick[TOX_MAX_NAME_LENGTH];
uint16_t n_len = tox_get_name(m, num, nick); uint16_t n_len = tox_get_name(m, num, nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH);
nick[n_len] = '\0'; nick[n_len] = '\0';
uint8_t msg[MAX_STR_SIZE]; uint8_t msg[MAX_STR_SIZE];
@ -239,6 +239,7 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, uint8
} else { } else {
uint8_t nick[TOX_MAX_NAME_LENGTH]; uint8_t nick[TOX_MAX_NAME_LENGTH];
uint16_t n_len = tox_get_name(m, num, nick); uint16_t n_len = tox_get_name(m, num, nick);
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH);
nick[n_len] = '\0'; nick[n_len] = '\0';
uint8_t msg[MAX_STR_SIZE]; uint8_t msg[MAX_STR_SIZE];

View File

@ -58,9 +58,11 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
groupchats[i].peer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH); groupchats[i].peer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH);
groupchats[i].oldpeer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH); groupchats[i].oldpeer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH);
groupchats[i].peer_name_lengths = malloc(sizeof(uint16_t)); groupchats[i].peer_name_lengths = malloc(sizeof(uint16_t));
groupchats[i].oldpeer_name_lengths = malloc(sizeof(uint16_t));
/* temp fix */ /* temp fix */
memcpy(&groupchats[i].oldpeer_names[0], UNKNOWN_NAME, sizeof(UNKNOWN_NAME)); memcpy(&groupchats[i].oldpeer_names[0], UNKNOWN_NAME, sizeof(UNKNOWN_NAME));
groupchats[i].oldpeer_name_lengths[0] = (uint16_t) strlen(UNKNOWN_NAME);
set_active_window(groupchats[i].chatwin); set_active_window(groupchats[i].chatwin);
@ -95,6 +97,7 @@ static void close_groupchat(ToxWindow *self, Tox *m, int groupnum)
free(groupchats[groupnum].peer_names); free(groupchats[groupnum].peer_names);
free(groupchats[groupnum].oldpeer_names); free(groupchats[groupnum].oldpeer_names);
free(groupchats[groupnum].peer_name_lengths); free(groupchats[groupnum].peer_name_lengths);
free(groupchats[groupnum].oldpeer_name_lengths);
memset(&groupchats[groupnum], 0, sizeof(GroupChat)); memset(&groupchats[groupnum], 0, sizeof(GroupChat));
int i; int i;