diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-10-26 20:42:52 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-10-26 20:42:52 +0200 |
commit | 82cf68254614a70a22d4b1b08b5bb2ba96c9dbd7 (patch) | |
tree | a93239273714abe5e4a66bf7fd457dc831fd919b /src | |
parent | 963537079c7d5a9f9fb39355fb0e3b84a78eaa0b (diff) | |
download | ouroboros-82cf68254614a70a22d4b1b08b5bb2ba96c9dbd7.tar.gz ouroboros-82cf68254614a70a22d4b1b08b5bb2ba96c9dbd7.zip |
ipcpd: Fix bad lock in shim-udp
Diffstat (limited to 'src')
-rw-r--r-- | src/ipcpd/shim-udp/main.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index e4ab4fac..c90b47a2 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -272,6 +272,7 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr, } pthread_rwlock_rdlock(&ipcpi.state_lock); + pthread_rwlock_wrlock(&udp_data.flows_lock); /* reply to IRM */ fd = ipcp_flow_req_arr(getpid(), dst_name, src_ae_name); @@ -283,8 +284,6 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr, return -1; } - pthread_rwlock_wrlock(&udp_data.flows_lock); - udp_data.uf_to_fd[skfd] = fd; udp_data.fd_to_uf[fd].skfd = skfd; udp_data.fd_to_uf[fd].udp = f_saddr.sin_port; @@ -494,19 +493,16 @@ static void * ipcp_udp_sdu_loop(void * o) pthread_rwlock_rdlock(&ipcpi.state_lock); pthread_rwlock_rdlock(&udp_data.flows_lock); - fd = udp_data.fd_to_uf[fd].skfd; - - pthread_rwlock_unlock(&udp_data.flows_lock); - pthread_rwlock_unlock(&ipcpi.state_lock); - - if (send(fd, + if (send(udp_data.fd_to_uf[fd].skfd, shm_du_buff_head(sdb), shm_du_buff_tail(sdb) - shm_du_buff_head(sdb), 0) < 0) LOG_ERR("Failed to send SDU."); - ipcp_flow_del(sdb); - } + pthread_rwlock_unlock(&udp_data.flows_lock); + pthread_rwlock_unlock(&ipcpi.state_lock); + + ipcp_flow_del(sdb); } } return (void *) 1; @@ -1119,10 +1115,13 @@ static int ipcp_udp_flow_dealloc(int fd) clr_fd(skfd); pthread_rwlock_unlock(&udp_data.flows_lock); - pthread_rwlock_unlock(&ipcpi.state_lock); + pthread_rwlock_wrlock(&udp_data.flows_lock); close(skfd); + pthread_rwlock_unlock(&udp_data.flows_lock); + pthread_rwlock_unlock(&ipcpi.state_lock); + flow_dealloc(fd); LOG_DBG("Flow with fd %d deallocated.", fd); |