Skip to content

Conversation

@GUIDINGLI
Copy link
Contributor

@GUIDINGLI GUIDINGLI commented Dec 8, 2025

Summary

This PR addresses two issues in NuttX resource and error handling:

Environment Resource Cleanup:
In group_leave.c, the unnecessary #ifndef CONFIG_DISABLE_ENVIRON conditional has been removed. Now, env_release(group) is always called when a group is released, regardless of configuration. This ensures environment variables are reliably cleaned up, reducing the risk of resource leaks especially under corner cases or configuration changes.

Improved Error Handling in Binfmt:
In binfmt_execmodule.c, redundant or misplaced return statements in the error handling code have been fixed, ensuring proper module cleanup and return value handling during exec failures.

These changes improve NuttX's robustness by enforcing more consistent and defensive resource management and error handling.

Impact

Reliability: Strengthens system stability by ensuring task groups always release their environment resources when the last member exits.
Maintainability: Code is cleaner and less dependent on conditional compilation flags, aiding future maintenance.
No API Change: This PR does not introduce any API change and is fully backward compatible.
Compatibility: The resource management logic is now configuration-independent, making it safer for future config changes and custom builds.

Testing

All changes were built and tested under the NuttX simulator (sim:nsh configuration).
Conducted the following tests:
Created and exited multiple tasks and processes to validate group and environment resource release.
Checked for regressions, crashes, and leaks with OSTest.
Verified resource cleanup using allocator logs and valgrind reports.
Host environment: x86_64 Linux
Board/target: Simulator (sim)
No resource leaks or abnormal behaviors were detected.

@GUIDINGLI GUIDINGLI marked this pull request as draft December 8, 2025 10:25
@github-actions github-actions bot added Area: OS Components OS Components issues Area: BINFMT Size: XS The size of the change in this PR is very small labels Dec 8, 2025
@GUIDINGLI GUIDINGLI self-assigned this Dec 8, 2025
@GUIDINGLI GUIDINGLI marked this pull request as ready for review December 8, 2025 10:50
@GUIDINGLI GUIDINGLI changed the title env bug fix Improve the robustness of env & binfmt code Dec 8, 2025
Remove unnecessary #ifdef CONFIG_DISABLE_ENVIRON.
This makes sure environment resources are always cleaned up,
regardless of configuration.

Signed-off-by: ligd <[email protected]>
xiaoxiang781216
xiaoxiang781216 previously approved these changes Dec 8, 2025
@xiaoxiang781216
Copy link
Contributor

@GUIDINGLI please fix the warning:

In file included from group/group_leave.c:45:
group/group_leave.c: In function 'group_release':
Error: /github/workspace/sources/nuttx/sched/environ/environ.h:39:32: error: statement with no effect [-Werror=unused-value]
   39 | #  define env_release(group)   (0)

Remove an extra return statement in exec_module failure path,
ensuring proper cleanup when errors occurs.

Signed-off-by: ligd <[email protected]>
@GUIDINGLI
Copy link
Contributor Author

@GUIDINGLI please fix the warning:

In file included from group/group_leave.c:45:
group/group_leave.c: In function 'group_release':
Error: /github/workspace/sources/nuttx/sched/environ/environ.h:39:32: error: statement with no effect [-Werror=unused-value]
   39 | #  define env_release(group)   (0)

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BINFMT Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants