Improve patty_ax25_sock_destroy() for raw sockets

Changes:

    * Don't clear socket from an interface's promiscuous socket table if
      the socket state is not SOCK_PROMISC

    * Destroy socket TNC if socket type is SOCK_RAW

    * Only attempt to close socket file descriptors >0
This commit is contained in:
XANTRONIX Development 2020-08-11 02:01:31 -04:00 committed by XANTRONIX Industrial
parent acaa5dee0f
commit a1ec1e00d0

View file

@ -186,16 +186,16 @@ error_malloc_sock:
} }
void patty_ax25_sock_destroy(patty_ax25_sock *sock) { void patty_ax25_sock_destroy(patty_ax25_sock *sock) {
if (sock->fd) { if (sock->type == PATTY_AX25_SOCK_RAW) {
if (sock->iface) { if (sock->state == PATTY_AX25_SOCK_PROMISC) {
(void)patty_ax25_if_promisc_delete(sock->iface, sock->fd); (void)patty_ax25_if_promisc_delete(sock->iface, sock->fd);
} }
close(sock->fd); patty_kiss_tnc_destroy(sock->raw);
} }
if (sock->raw) { if (sock->fd > 0) {
patty_kiss_tnc_destroy(sock->raw); (void)close(sock->fd);
} }
free(sock->tx_slots); free(sock->tx_slots);