Deinit ncurses before fatal crash
This commit is contained in:
parent
87b3f984c1
commit
eb3a859e97
4 changed files with 18 additions and 12 deletions
|
@ -22,6 +22,7 @@ void draw_border(WINDOW *window, bool active);
|
|||
void add_message(uint8_t *author, uint8_t *recipient, uint8_t *content, uint32_t length, time_t creation);
|
||||
void show_chat(uint8_t *recipient);
|
||||
void add_username(char *username);
|
||||
void ncurses_deinit();
|
||||
void ui();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -214,11 +214,7 @@ int verify_packet(packet_t *pkt, int fd)
|
|||
int status = recv_packet(pkt, fd, ZSM_TYP_MESSAGE);
|
||||
if (status != ZSM_STA_SUCCESS) {
|
||||
close(fd);
|
||||
if (status == ZSM_STA_CLOSED_CONNECTION) {
|
||||
error(1, "Server closed connection");
|
||||
}
|
||||
|
||||
return ZSM_STA_ERROR_INTEGRITY;
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t from[MAX_NAME], to[MAX_NAME];
|
||||
|
|
|
@ -66,7 +66,12 @@ void *receive_worker(void *arg)
|
|||
|
||||
while (1) {
|
||||
packet_t pkt;
|
||||
if (verify_packet(&pkt, sockfd) != ZSM_STA_SUCCESS) {
|
||||
int status = verify_packet(&pkt, sockfd);
|
||||
if (status != ZSM_STA_SUCCESS) {
|
||||
if (status == ZSM_STA_CLOSED_CONNECTION) {
|
||||
ncurses_deinit();
|
||||
error(1, "Server closed connection");
|
||||
}
|
||||
error(0, "Error verifying packet");
|
||||
}
|
||||
size_t cipher_len = pkt.length - NONCE_SIZE - MAX_NAME * 2;
|
||||
|
|
|
@ -539,6 +539,13 @@ void send_message()
|
|||
show_chat(recipient);
|
||||
}
|
||||
|
||||
void ncurses_deinit()
|
||||
{
|
||||
arraylist_free(users);
|
||||
arraylist_free(marked);
|
||||
endwin();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main loop of user interface
|
||||
*/
|
||||
|
@ -577,7 +584,8 @@ void ui(int fd)
|
|||
ch = getch();
|
||||
switch (ch) {
|
||||
case CTRLD:
|
||||
goto cleanup;
|
||||
ncurses_deinit();
|
||||
break;
|
||||
|
||||
/* go up by k or up arrow */
|
||||
case UP:
|
||||
|
@ -617,16 +625,12 @@ void ui(int fd)
|
|||
curs_pos = 0;
|
||||
content[0] = '\0';
|
||||
}
|
||||
|
||||
default:
|
||||
if (current_window == CHAT_WINDOW)
|
||||
get_chatbox_content(ch);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
arraylist_free(users);
|
||||
arraylist_free(marked);
|
||||
endwin();
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue