Files
nuttx/fs
dongjiuzhu1 cd8e3e18a8 fs/file: add reference count protection for stack-allocated file structures
Issue:
When using a stack-allocated file structure, the sequence:
1. file_open() initializes the stack file structure
2. file_mmap() creates memory mapping and increments reference count
3. file_munmap() decrements reference count and may free the file structure
4. file_close() attempts to close already freed structure → crash

Root cause:
The memory mapping operations (fs_reffilep/fs_putfilep) manage reference counts
independently and can free the stack-allocated file structure prematurely.

Solution:
- Add reference count protection during file_open() for stack-allocated files
- Clear reference count appropriately during file_close()
- This ensures the file structure remains valid throughout its lifetime

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2026-01-01 17:06:17 +08:00
..