Skip to content

Commit

Permalink
deps: uvwasi: cherry-pick 64e59d5
Browse files Browse the repository at this point in the history
Original commit message:

    This commit ensures that multiple calls to uvwasi_destroy()
    are possible. Prior to this commit, subsequent calls to
    destroy() would abort because the file table's rwlock was
    incorrectly being destroyed multiple times.

PR-URL: #31076
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
cjihrig authored and BridgeAR committed Jan 3, 2020
1 parent baf8730 commit a5937c7
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions deps/uvwasi/src/fd_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,20 @@ void uvwasi_fd_table_free(uvwasi_t* uvwasi, struct uvwasi_fd_table_t* table) {
uvwasi__free(uvwasi, entry);
}

uvwasi__free(uvwasi, table->fds);
table->fds = NULL;
table->size = 0;
table->used = 0;
uv_rwlock_destroy(&table->rwlock);
if (table->fds != NULL) {
/* It's fine to call uvwasi__free() multiple times on table->fds. However,
it is not fine to call uv_rwlock_destroy() multiple times. Guard against
that by ensuring that table->fds is not NULL. Technically, it's possible
that uvwasi_fd_table_init() initialized the rwlock successfully, but
failed to initialize fds. However, the only way that's possible is if
the application already ran out of memory.
*/
uvwasi__free(uvwasi, table->fds);
table->fds = NULL;
table->size = 0;
table->used = 0;
uv_rwlock_destroy(&table->rwlock);
}
}


Expand Down

0 comments on commit a5937c7

Please sign in to comment.