mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
fix(stdio): check close_p return before decrementing fd count
If entry->ops->close_p() fails, do not decrement s_open_count to prevent FD count corruption. Return early with the error code instead.
This commit is contained in:
@@ -151,6 +151,9 @@ int console_close(__attribute__((unused)) void *ctx, int fd)
|
||||
}
|
||||
|
||||
int ret = entry->ops->close_p(entry->vfs_ctx, fd);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Close auxiliaries when last console fd is closed */
|
||||
_lock_acquire(&s_lock);
|
||||
@@ -168,7 +171,7 @@ int console_close(__attribute__((unused)) void *ctx, int fd)
|
||||
}
|
||||
_lock_release(&s_lock);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t console_write(__attribute__((unused)) void *ctx, int fd, const void *data, size_t size)
|
||||
|
||||
Reference in New Issue
Block a user