From 8ca960fa0274018cb4f94a1826029d74e6f762e0 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 21 Jun 2021 20:24:03 +0200 Subject: lib, ipcpd, irmd: Wrap pthread unlocks for cleanup This add an ouroboros/pthread.h header that wraps the pthread_..._unlock() functions for cleanup using pthread_cleanup_push() as this casting is not safe (and there were definitely bad casts in the code). The close() function is now also wrapped for cleanup in ouroboros/sockets.h. This allows enabling more compiler checks. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/udp/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/ipcpd/udp/main.c') diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c index 13db0c1f..03de24ab 100644 --- a/src/ipcpd/udp/main.c +++ b/src/ipcpd/udp/main.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "ipcp.h" #include "shim-data.h" @@ -51,7 +52,6 @@ #include #include #include -#include #include #include @@ -393,8 +393,7 @@ static void * ipcp_udp_mgmt_handler(void * o) { (void) o; - pthread_cleanup_push((void (*)(void *)) pthread_mutex_unlock, - (void *) &udp_data.mgmt_lock); + pthread_cleanup_push(__cleanup_mutex_unlock, &udp_data.mgmt_lock); while (true) { struct mgmt_frame * frame; @@ -485,9 +484,14 @@ static void * ipcp_udp_packet_reader(void * o) return 0; } -static void cleanup_writer(void * o) +static void cleanup_fqueue(void * fq) { - fqueue_destroy((fqueue_t *) o); + fqueue_destroy((fqueue_t *) fq); +} + +static void cleanup_sdb(void * sdb) +{ + ipcp_sdb_release((struct shm_du_buff *) sdb); } static void * ipcp_udp_packet_writer(void * o) @@ -502,7 +506,7 @@ static void * ipcp_udp_packet_writer(void * o) ipcp_lock_to_core(); - pthread_cleanup_push(cleanup_writer, fq); + pthread_cleanup_push(cleanup_fqueue, fq); while (true) { struct sockaddr_in saddr; @@ -545,8 +549,7 @@ static void * ipcp_udp_packet_writer(void * o) memcpy(buf, &eid, sizeof(eid)); - pthread_cleanup_push((void (*)(void *)) - ipcp_sdb_release, (void *) sdb); + pthread_cleanup_push(cleanup_sdb, sdb); if (sendto(udp_data.s_fd, buf, len + OUR_HEADER_LEN, MSG_CONFIRM, -- cgit v1.2.3