Repository navigation
sched/semaphore: Check the semaphore before using it in nxsem_destroy() - #22269
Merged
Merged
Conversation
nxsem_destroy() read the flags of the semaphore to set up its locals before DEBUGASSERT(sem != NULL), so a NULL semaphore faulted before the assertion could report it. Set the locals up after the check. Signed-off-by: hujun5 <hujun5@xiaomi.com> Signed-off-by: ganjing <ganjing@xiaomi.com>
Shanks0224
requested review from
GUIDINGLI,
jerpelea and
pussuw
as code owners
November 24, 2026 11:56
xiaoxiang781216
approved these changes
Nov 24, 2026
|
Contributor
Author
|
@GUIDINGLI PTAL |
GUIDINGLI
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Please adhere to Contributing Guidelines.
Summary
nxsem_destroy()read the flags of the semaphore to set up its localsbefore
DEBUGASSERT(sem != NULL), so a NULL semaphore faulted before theassertion could report it. Set the locals up after the check.
Impact
No functional change for a valid semaphore. With
CONFIG_DEBUG_ASSERTIONS, a NULL semaphore is now reported by theassertion instead of faulting. No impact on the build system,
documentation or hardware.
Testing
Build host: Linux x86_64.
sim:nsh+CONFIG_TESTING_OSTEST+CONFIG_CANCELLATION_POINTS, fullostest:
sim:nshbuilds with no warning. No regression test: the change onlymoves the use of the pointer after its assertion, and a NULL semaphore
stops the system with or without it.