Skip to content

Commit

Permalink
Fix missing conn_t locks
Browse files Browse the repository at this point in the history
The conn_t lock must be held by the caller for conn_setup and
reactivate_connection.

Ref: axel-download-accelerator#294
Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
  • Loading branch information
ismaell committed May 3, 2020
1 parent 23e807d commit 1d55a6e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/axel.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ axel_start(axel_t *axel)

for (i = 0; i < axel->conf->num_connections; i++) {
if (axel->conn[i].currentbyte > axel->conn[i].lastbyte) {
pthread_mutex_lock(&axel->conn[i].lock);
reactivate_connection(axel, i);
pthread_mutex_unlock(&axel->conn[i].lock);
} else if (axel->conn[i].currentbyte < axel->conn[i].lastbyte) {
if (axel->conf->verbose >= 2) {
axel_message(axel,
Expand Down
2 changes: 2 additions & 0 deletions src/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,10 @@ conn_info(conn_t *conn)

conn->supported = true;
conn->currentbyte = 0;
pthread_mutex_lock(&conn->lock);
if (!conn_setup(conn))
return 0;
pthread_mutex_unlock(&conn->lock);
conn_exec(conn);
conn_disconnect(conn);

Expand Down
10 changes: 9 additions & 1 deletion src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,17 @@ search_makelist(search_t *results, char *orig_url)
memset(conn, 0, sizeof(conn_t));
conn->conf = results->conf;

if (!conn_set(conn, s) || !conn_setup(conn) || !conn_exec(conn))
if (!conn_set(conn, s))
goto done;

{
pthread_mutex_unlock(&conn->lock);
int tmp = conn_setup(conn);
pthread_mutex_unlock(&conn->lock);
if (!tmp || !conn_exec(conn))
goto done;
}

{
int j = 0;

Expand Down

0 comments on commit 1d55a6e

Please sign in to comment.