casaroli opened a new pull request, #22585: URL: https://github.com/apache/nuttx/pull/22585
## Summary A shm object with a hard link was never freed. `link()` of a shm object (for example `/var/shm/a` to `/var/shm/b`, with `CONFIG_FS_LINKS`) adds `INODE_NLINK_INC` to the reference count of the inode. `shmfs_release()` and `shmfs_unlink()` free the object only when the count is small, so they do not free it while the link exists. When the last name went, the removal of the hard link (`fs/inode/fs_inoderemove.c`) freed the inode with `inode_free()`, but nothing freed the object: the object and all its memory were lost. Now `inode_free()` frees the object of a shm inode, as the data of a file goes with its inode. When the last close, `munmap()` or `unlink()` freed the object before, `i_private` is NULL and `shmfs_free_object()` does nothing. `inode_free()` is the one place for the two ways the inode goes: the removal of the last hard link and the release of the last reference (`fs/inode/fs_inoderelease.c`). ## Impact Only with `CONFIG_FS_SHMFS`. No change for a shm object without a hard link. The same in flat, protected and kernel builds. ## Testing The apps PR adds `test_nuttx_fs_shmlink01` to `cmocka_fs_test`: it makes a 64 KiB shm object, maps it, links a second name to it, removes the first name, closes and unmaps it, reads the data through the second name, removes the second name, and checks with `mallinfo()` that the memory is free again. | Configuration | master 1af7ac541e4 | this PR | |---|---|---| | rv-virt:citest (flat, riscv32, QEMU TCG; a CI configuration) | shmlink01 FAIL (`after.uordblks <= before.uordblks + SHMLINK_SLACK`) | shmlink01 OK; whole `cmocka_fs_test`: 50 of 50 pass | | qemu-armv8a:nsh (flat, arm64, QEMU TCG) + `CM_FS_TEST`, `FS_SHMFS` | shmlink01 FAIL | shmlink01 OK; whole `cmocka_fs_test`: 48 of 48 pass | | rv-virt:nsh64 (flat, riscv64, QEMU TCG) + `CM_FS_TEST`, `FS_SHMFS` | shmlink01 FAIL; `free` after it: Umem used 81560 | shmlink01 OK; Umem used 15944 | Builds with the CI image (`-Werror`): the configurations above, rv-virt:pnsh64 (protected) + `FS_SHMFS`, rv-virt:knsh64 (kernel) + `FS_SHMFS`, qemu-intel64:nsh (x86_64) + `FS_SHMFS`, `FS_LINKS`, and sim:citest: all OK. `tools/checkpatch.sh -c -u -m -g`: pass. -- 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]
