fd_object_release: Preserve errno (#2535)

Preserve errno because this function is often used like
the following. The caller wants to report the error from the main
operation (`lseek` in this example), not from fd_object_release.

```
    off_t ret = lseek(fd_number(fo), offset, nwhence);
    fd_object_release(fo);
    if (ret < 0)
        return convert_errno(errno);
```
This commit is contained in:
YAMAMOTO Takashi 2023-09-08 13:26:32 +09:00 committed by GitHub
parent 534a8cf9f4
commit f128150d43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -642,6 +642,7 @@ static void
fd_object_release(struct fd_object *fo) UNLOCKS(fo->refcount)
{
if (refcount_release(&fo->refcount)) {
int saved_errno = errno;
switch (fo->type) {
case __WASI_FILETYPE_DIRECTORY:
// For directories we may keep track of a DIR object. Calling
@ -659,6 +660,7 @@ fd_object_release(struct fd_object *fo) UNLOCKS(fo->refcount)
break;
}
wasm_runtime_free(fo);
errno = saved_errno;
}
}