summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2020-01-17 05:11:37 +0100
committerGravatar Nikias Bassen2020-01-17 05:11:37 +0100
commit7c7a897e1e2e63c2aa9416844bd96b2910b81479 (patch)
treeb0d529129c7ebab2ec37ce9474f9573666e868f9 /src
parentec5ff91cfabd30637f8af8f5c79baf4d7818ce57 (diff)
downloadusbmuxd-7c7a897e1e2e63c2aa9416844bd96b2910b81479.tar.gz
usbmuxd-7c7a897e1e2e63c2aa9416844bd96b2910b81479.tar.bz2
device: Fix potential deadlock (#130)
Diffstat (limited to 'src')
-rw-r--r--src/device.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/device.c b/src/device.c
index 87a36cc..5e32ce2 100644
--- a/src/device.c
+++ b/src/device.c
@@ -147,7 +147,6 @@ static struct mux_device* get_mux_device_for_id(int device_id)
static struct mux_connection* get_mux_connection(int device_id, struct mux_client *client)
{
struct mux_connection *conn = NULL;
- pthread_mutex_lock(&device_list_mutex);
FOREACH(struct mux_device *dev, &device_list) {
if(dev->id == device_id) {
FOREACH(struct mux_connection *lconn, &dev->connections) {
@@ -159,7 +158,6 @@ static struct mux_connection* get_mux_connection(int device_id, struct mux_clien
break;
}
} ENDFOREACH
- pthread_mutex_unlock(&device_list_mutex);
return conn;
}
@@ -466,8 +464,9 @@ static int send_tcp_ack(struct mux_connection *conn)
*/
void device_client_process(int device_id, struct mux_client *client, short events)
{
+ pthread_mutex_lock(&device_list_mutex);
struct mux_connection *conn = get_mux_connection(device_id, client);
-
+ pthread_mutex_unlock(&device_list_mutex);
if(!conn) {
usbmuxd_log(LL_WARNING, "Could not find connection for device %d client %p", device_id, client);
return;