Skip to content

Commit

Permalink
unlock all fd mutexes in reverse order
Browse files Browse the repository at this point in the history
Some functions acquire mutexes for multiple file descriptors.
This commit ensures that the mutexes are released in the
reverse order that they are aquired.
  • Loading branch information
cjihrig committed Jan 22, 2020
1 parent b19cfa5 commit ea73af5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/fd_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ uvwasi_errno_t uvwasi_fd_table_renumber(struct uvwasi_s* uvwasi,
r = uv_fs_close(NULL, &req, dst_entry->fd, NULL);
uv_fs_req_cleanup(&req);
if (r != 0) {
uv_mutex_unlock(&dst_entry->mutex);
uv_mutex_unlock(&src_entry->mutex);
uv_mutex_unlock(&dst_entry->mutex);
err = uvwasi__translate_uv_error(r);
goto exit;
}
Expand Down
8 changes: 4 additions & 4 deletions src/uvwasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1821,9 +1821,9 @@ uvwasi_errno_t uvwasi_path_link(uvwasi_t* uvwasi,

err = UVWASI_ESUCCESS;
exit:
uv_mutex_unlock(&old_wrap->mutex);
uv_mutex_unlock(&new_wrap->mutex);
if (old_fd != new_fd)
uv_mutex_unlock(&new_wrap->mutex);
uv_mutex_unlock(&old_wrap->mutex);
return err;
}

Expand Down Expand Up @@ -2136,9 +2136,9 @@ uvwasi_errno_t uvwasi_path_rename(uvwasi_t* uvwasi,

err = UVWASI_ESUCCESS;
exit:
uv_mutex_unlock(&old_wrap->mutex);
uv_mutex_unlock(&new_wrap->mutex);
if (old_fd != new_fd)
uv_mutex_unlock(&new_wrap->mutex);
uv_mutex_unlock(&old_wrap->mutex);

return err;
}
Expand Down

0 comments on commit ea73af5

Please sign in to comment.