Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6784296

Browse filesBrowse files
cjihrigtargos
authored andcommitted
deps: uvwasi: cherry-pick 75b389c
Original commit message: This commit changes the memory management in uvwasi_fd_table_init() such that ENOMEM errors can be handled better in uvwasi_fd_table_free(). PR-URL: #31076 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent a9d9fdb commit 6784296
Copy full SHA for 6784296

File tree

Expand file treeCollapse file tree

1 file changed

+13
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-14
lines changed
Open diff view settings
Collapse file

‎deps/uvwasi/src/fd_table.c‎

Copy file name to clipboardExpand all lines: deps/uvwasi/src/fd_table.c
+13-14Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,25 @@ uvwasi_errno_t uvwasi_fd_table_init(uvwasi_t* uvwasi,
291291
return UVWASI_EINVAL;
292292

293293
table->fds = NULL;
294-
r = uv_rwlock_init(&table->rwlock);
295-
if (r != 0)
296-
return uvwasi__translate_uv_error(r);
297-
298294
table->used = 0;
299295
table->size = init_size;
300296
table->fds = uvwasi__calloc(uvwasi,
301297
init_size,
302298
sizeof(struct uvwasi_fd_wrap_t*));
303299

304-
if (table->fds == NULL) {
305-
err = UVWASI_ENOMEM;
306-
goto error_exit;
300+
if (table->fds == NULL)
301+
return UVWASI_ENOMEM;
302+
303+
r = uv_rwlock_init(&table->rwlock);
304+
if (r != 0) {
305+
err = uvwasi__translate_uv_error(r);
306+
/* Free table->fds and set it to NULL here. This is done explicitly instead
307+
of jumping to error_exit because uvwasi_fd_table_free() relies on fds
308+
being NULL to know whether or not to destroy the rwlock.
309+
*/
310+
uvwasi__free(uvwasi, table->fds);
311+
table->fds = NULL;
312+
return err;
307313
}
308314

309315
/* Create the stdio FDs. */
@@ -358,13 +364,6 @@ void uvwasi_fd_table_free(uvwasi_t* uvwasi, struct uvwasi_fd_table_t* table) {
358364
}
359365

360366
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-
*/
368367
uvwasi__free(uvwasi, table->fds);
369368
table->fds = NULL;
370369
table->size = 0;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.