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

Close file handlers when inbound file transfer fails

This commit is contained in:
jfreegman 2020-11-03 13:26:23 -05:00
parent 1a723f0e8e
commit f64300d1d6
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63

View File

@ -610,8 +610,7 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
char *file_path = malloc(file_path_buf_size); char *file_path = malloc(file_path_buf_size);
if (file_path == NULL) { if (file_path == NULL) {
tox_file_control(m, friendnum, filenum, TOX_FILE_CONTROL_CANCEL, NULL); close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, "File transfer failed: Out of memory.", notif_error);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer failed: Out of memory.");
return; return;
} }
@ -626,8 +625,7 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
} }
if (path_len >= file_path_buf_size || path_len >= sizeof(ft->file_path) || name_length >= sizeof(ft->file_name)) { if (path_len >= file_path_buf_size || path_len >= sizeof(ft->file_path) || name_length >= sizeof(ft->file_name)) {
tox_file_control(m, friendnum, filenum, TOX_FILE_CONTROL_CANCEL, NULL); close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, "File transfer failed: File path too long.", notif_error);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer faield: File path too long.");
free(file_path); free(file_path);
return; return;
} }
@ -645,8 +643,7 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
size_t d_len = strlen(d); size_t d_len = strlen(d);
if (path_len + d_len >= file_path_buf_size) { if (path_len + d_len >= file_path_buf_size) {
tox_file_control(m, friendnum, filenum, TOX_FILE_CONTROL_CANCEL, NULL); close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, "File transfer failed: File path too long.", notif_error);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer failed: File path too long.");
free(file_path); free(file_path);
return; return;
} }
@ -655,8 +652,7 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
file_path[path_len + d_len] = '\0'; file_path[path_len + d_len] = '\0';
if (++count > 99) { // If there are this many duplicate file names we should probably give up if (++count > 99) { // If there are this many duplicate file names we should probably give up
tox_file_control(m, friendnum, filenum, TOX_FILE_CONTROL_CANCEL, NULL); close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, "File transfer failed: invalid file path.", notif_error);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer failed: invalid file path.");
free(file_path); free(file_path);
return; return;
} }