mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-03-11 16:35:33 +00:00
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:
parent
534a8cf9f4
commit
f128150d43
|
@ -642,6 +642,7 @@ static void
|
||||||
fd_object_release(struct fd_object *fo) UNLOCKS(fo->refcount)
|
fd_object_release(struct fd_object *fo) UNLOCKS(fo->refcount)
|
||||||
{
|
{
|
||||||
if (refcount_release(&fo->refcount)) {
|
if (refcount_release(&fo->refcount)) {
|
||||||
|
int saved_errno = errno;
|
||||||
switch (fo->type) {
|
switch (fo->type) {
|
||||||
case __WASI_FILETYPE_DIRECTORY:
|
case __WASI_FILETYPE_DIRECTORY:
|
||||||
// For directories we may keep track of a DIR object. Calling
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
wasm_runtime_free(fo);
|
wasm_runtime_free(fo);
|
||||||
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user