From ea73af5e0e1e291521ac6260b6d90e04f5c42641 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 21 Jan 2020 09:29:36 -0500 Subject: [PATCH] unlock all fd mutexes in reverse order Some functions acquire mutexes for multiple file descriptors. This commit ensures that the mutexes are released in the reverse order that they are aquired. --- src/fd_table.c | 2 +- src/uvwasi.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/fd_table.c b/src/fd_table.c index b6a43f0..e489776 100644 --- a/src/fd_table.c +++ b/src/fd_table.c @@ -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; } diff --git a/src/uvwasi.c b/src/uvwasi.c index 5a73bfe..e4c2ac6 100644 --- a/src/uvwasi.c +++ b/src/uvwasi.c @@ -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; } @@ -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; }