From 5fe9706b823cd441703239ece020e517d722d88c Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sun, 15 May 2016 15:43:47 +0200 Subject: lib: cleanup file descriptors for shared memory cleanup of file descriptors for the shared memory. also adds a missing NULL check and some invalidation in dev.c --- src/lib/dev.c | 11 +++++++++-- src/lib/shm_ap_rbuff.c | 6 ++++++ src/lib/shm_du_map.c | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/dev.c b/src/lib/dev.c index 4b5e56be..55e4dc17 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -249,6 +249,9 @@ int flow_accept(int fd, irm_msg_t * recv_msg = NULL; int cfd = -1; + if (ap_name == NULL) + return -1; + msg.code = IRM_MSG_CODE__IRM_FLOW_ACCEPT; msg.has_pid = true; @@ -466,11 +469,13 @@ int flow_dealloc(int fd) msg.code = IRM_MSG_CODE__IRM_FLOW_DEALLOC; msg.has_port_id = true; - rw_lock_rdlock(&_ap_instance->flows_lock); + rw_lock_wrlock(&_ap_instance->flows_lock); msg.port_id = _ap_instance->flows[fd].port_id; - rw_lock_unlock(&_ap_instance->flows_lock); + _ap_instance->flows[fd].port_id = -1; + shm_ap_rbuff_close(_ap_instance->flows[fd].rb); + _ap_instance->flows[fd].rb = NULL; rw_lock_wrlock(&_ap_instance->data_lock); @@ -478,6 +483,8 @@ int flow_dealloc(int fd) rw_lock_unlock(&_ap_instance->data_lock); + rw_lock_unlock(&_ap_instance->flows_lock); + recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) return -1; diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c index 0524a96c..71a7e733 100644 --- a/src/lib/shm_ap_rbuff.c +++ b/src/lib/shm_ap_rbuff.c @@ -180,6 +180,9 @@ void shm_ap_rbuff_close(struct shm_ap_rbuff * rb) return; } + if (close(rb->fd) < 0) + LOG_DBGF("Couldn't close shared memory."); + if (munmap(rb->shm_base, SHM_RBUFF_FILE_SIZE) == -1) LOG_DBGF("Couldn't unmap shared memory."); @@ -200,6 +203,9 @@ void shm_ap_rbuff_destroy(struct shm_ap_rbuff * rb) return; } + if (close(rb->fd) < 0) + LOG_DBGF("Couldn't close shared memory."); + sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", rb->pid); if (munmap(rb->shm_base, SHM_RBUFF_FILE_SIZE) == -1) diff --git a/src/lib/shm_du_map.c b/src/lib/shm_du_map.c index 71c15731..7099b265 100644 --- a/src/lib/shm_du_map.c +++ b/src/lib/shm_du_map.c @@ -199,6 +199,9 @@ void shm_du_map_close(struct shm_du_map * dum) return; } + if (close(dum->fd) < 0) + LOG_DBGF("Couldn't close shared memory."); + if (munmap(dum->shm_base, SHM_FILE_SIZE) == -1) LOG_DBGF("Couldn't unmap shared memory."); @@ -212,6 +215,9 @@ void shm_du_map_destroy(struct shm_du_map * dum) return; } + if (close(dum->fd) < 0) + LOG_DBGF("Couldn't close shared memory."); + if (munmap(dum->shm_base, SHM_FILE_SIZE) == -1) LOG_DBGF("Couldn't unmap shared memory."); -- cgit v1.2.3