Skip to content

Commit a9d9fdb

Browse files
cjihrigtargos
authored andcommitted
deps: uvwasi: cherry-pick 64e59d5
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]>
1 parent cc3e427 commit a9d9fdb

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

deps/uvwasi/src/fd_table.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,20 @@ void uvwasi_fd_table_free(uvwasi_t* uvwasi, struct uvwasi_fd_table_t* table) {
357357
uvwasi__free(uvwasi, entry);
358358
}
359359

360-
uvwasi__free(uvwasi, table->fds);
361-
table->fds = NULL;
362-
table->size = 0;
363-
table->used = 0;
364-
uv_rwlock_destroy(&table->rwlock);
360+
if (table->fds != NULL) {
361+
/* It's fine to call uvwasi__free() multiple times on table->fds. However,
362+
it is not fine to call uv_rwlock_destroy() multiple times. Guard against
363+
that by ensuring that table->fds is not NULL. Technically, it's possible
364+
that uvwasi_fd_table_init() initialized the rwlock successfully, but
365+
failed to initialize fds. However, the only way that's possible is if
366+
the application already ran out of memory.
367+
*/
368+
uvwasi__free(uvwasi, table->fds);
369+
table->fds = NULL;
370+
table->size = 0;
371+
table->used = 0;
372+
uv_rwlock_destroy(&table->rwlock);
373+
}
365374
}
366375

367376

0 commit comments

Comments
 (0)