jingfei195887 opened a new pull request, #21677: URL: https://github.com/apache/nuttx/pull/21677
## Summary `shmfs_unlink()` frees the backing object only when `i_crefs <= 1`. When `file_shm_unlink()` calls it, the inode still holds the reference taken by `inode_find()` and the reference of the inode tree, so `i_crefs` is at least 2 and the object is never freed on this path. If the last fd was already closed, `shmfs_release()` did not free it either, because the inode was still linked at that time, so the object leaks. Compare against 2 instead. With an fd or a mapping still open, `i_crefs` is larger and the object is left for `shmfs_release()` on the last close or munmap. ## Impact `shm_unlink()` of an object with no open fd or mapping now frees the object. Objects that are still open or mapped are unchanged. ## Testing Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master 03aea78639, `sim:nsh` with `CONFIG_FS_SHMFS=y`. A small test program checks the heap and the object contents: | case | master | this PR | |---|---|---| | `shm_open` + `ftruncate(64)` + `close` + `shm_unlink`, 20 times: heap growth | 1760 bytes | 0 | | unlink while mapped, then read the mapping | contents intact | contents intact | | unlink while an fd is open, then mmap again | contents intact | contents intact | - `./tools/checkpatch.sh -g master..HEAD`: all checks pass. - Make and CMake builds pass; `ostest` exits with status 0. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
