Skip to content

Commit 6c1b92d

Browse files
authored
Fix deadlock in conn cleanup (#244)
Calling through to request_free() from clean_req() causes deadlock since sshfs.lock is already held by the caller of clean_req().
1 parent d18869a commit 6c1b92d

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

sshfs.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,9 +1401,11 @@ static int sftp_read(struct conn *conn, uint8_t *type, struct buffer *buf)
14011401

14021402
static void request_free(struct request *req)
14031403
{
1404-
pthread_mutex_lock(&sshfs.lock);
1404+
if (req->end_func)
1405+
req->end_func(req);
1406+
14051407
req->conn->req_count--;
1406-
pthread_mutex_unlock(&sshfs.lock);
1408+
14071409
buf_free(&req->reply);
14081410
sem_destroy(&req->ready);
14091411
g_free(req);
@@ -1449,11 +1451,9 @@ static int clean_req(void *key, struct request *req, gpointer user_data)
14491451
req->error = -EIO;
14501452
if (req->want_reply)
14511453
sem_post(&req->ready);
1452-
else {
1453-
if (req->end_func)
1454-
req->end_func(req);
1454+
else
14551455
request_free(req);
1456-
}
1456+
14571457
return TRUE;
14581458
}
14591459

@@ -1515,12 +1515,9 @@ static int process_one_request(struct conn *conn)
15151515
if (req->want_reply)
15161516
sem_post(&req->ready);
15171517
else {
1518-
if (req->end_func) {
1519-
pthread_mutex_lock(&sshfs.lock);
1520-
req->end_func(req);
1521-
pthread_mutex_unlock(&sshfs.lock);
1522-
}
1518+
pthread_mutex_lock(&sshfs.lock);
15231519
request_free(req);
1520+
pthread_mutex_unlock(&sshfs.lock);
15241521
}
15251522
} else
15261523
buf_free(&buf);
@@ -1970,12 +1967,9 @@ static int sftp_request_wait(struct request *req, uint8_t type,
19701967
}
19711968

19721969
out:
1973-
if (req->end_func) {
1974-
pthread_mutex_lock(&sshfs.lock);
1975-
req->end_func(req);
1976-
pthread_mutex_unlock(&sshfs.lock);
1977-
}
1970+
pthread_mutex_lock(&sshfs.lock);
19781971
request_free(req);
1972+
pthread_mutex_unlock(&sshfs.lock);
19791973
return err;
19801974
}
19811975

0 commit comments

Comments
 (0)