nodejs / uvwasi

WASI syscall API built atop libuv
MIT License
226 stars 50 forks source link

Handle NULL pointers in uvwasi_destroy consistently #163

Closed gumb0 closed 3 years ago

gumb0 commented 3 years ago

uvwasi_destroy currently handles the case when NULL is passed as uvwasi https://github.com/nodejs/uvwasi/blob/adda15515cbb5a478d0ddb85602d987278a43384/src/uvwasi.c#L372-L373 and also when uvwasi->fds is NULL https://github.com/nodejs/uvwasi/blob/adda15515cbb5a478d0ddb85602d987278a43384/src/fd_table.c#L231-L232 but not the case when uvwasi->allocator is NULL.

I suggest for consistency to handle fully zeroed-out uvwasi passed to uvwasi_destroy. That would simplify client-side in that you wouldn't need to check whether uvwasi_init finished successfully when you call uvwasi_destroy.

P.S. Not sure if it would also make sense to add uvwasi->allocator = NULL; to uvwasi_destroy.