diff --git a/can.c b/can.c index 1de2a12..62fccf2 100644 --- a/can.c +++ b/can.c @@ -69,7 +69,6 @@ static void can_exit(struct ios_ops *ios) shutdown(ios->fd, SHUT_RDWR); close(ios->fd); pthread_join(can_thread, NULL); - free(ios); } static void *can_thread_fun(void *_data) diff --git a/commands.c b/commands.c index 6d6c0e9..3fc6fa4 100644 --- a/commands.c +++ b/commands.c @@ -147,7 +147,10 @@ static int cmd_break(int argc, char *argv[]) static int cmd_quit(int argc, char *argv[]) { + fflush(NULL); microcom_exit(0); + free(ios); + exit(0); return 0; } diff --git a/microcom.c b/microcom.c index 1218ec4..6376b07 100644 --- a/microcom.c +++ b/microcom.c @@ -150,12 +150,13 @@ int flag_to_baudrate(speed_t speed) void microcom_exit(int signal) { - printf("exiting\n"); + write(1, "exiting\n", 8); ios->exit(ios); tcsetattr(STDIN_FILENO, TCSANOW, &sots); - exit(0); + if (signal) + _Exit(0); } /******************************************************************** @@ -202,7 +203,7 @@ int listenonly = 0; int main(int argc, char *argv[]) { - struct sigaction sact; /* used to initialize the signal handler */ + struct sigaction sact = {0}; /* used to initialize the signal handler */ int opt, ret; char *hostport = NULL; int telnet = 0, can = 0; @@ -319,6 +320,7 @@ int main(int argc, char *argv[]) /* set the signal handler to restore the old * termios handler */ sact.sa_handler = µcom_exit; + sigemptyset(&sact.sa_mask); sigaction(SIGHUP, &sact, NULL); sigaction(SIGINT, &sact, NULL); sigaction(SIGPIPE, &sact, NULL); diff --git a/serial.c b/serial.c index 0778fe1..2bc39f2 100644 --- a/serial.c +++ b/serial.c @@ -136,7 +136,6 @@ static void serial_exit(struct ios_ops *ios) { tcsetattr(ios->fd, TCSANOW, &pots); close(ios->fd); - free(ios); serial_unlock(); } diff --git a/telnet.c b/telnet.c index fe30da7..f510888 100644 --- a/telnet.c +++ b/telnet.c @@ -76,7 +76,6 @@ static int telnet_send_break(struct ios_ops *ios) static void telnet_exit(struct ios_ops *ios) { close(ios->fd); - free(ios); } struct ios_ops *telnet_init(char *hostport)