Skip to content

sched/semaphore: Check the semaphore before using it in nxsem_destroy() - #22269

Merged
GUIDINGLI merged 1 commit into
apache:masterfrom
Shanks0224:sched-sem-destroy
Nov 25, 2026
Merged

GUIDINGLI merged 1 commit into
apache:masterfrom
Shanks0224:sched-sem-destroy

Conversation

@Shanks0224

Copy link
Copy Markdown
Contributor

Note: Please adhere to Contributing Guidelines.

Summary

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.

Impact

No functional change for a valid semaphore. With
CONFIG_DEBUG_ASSERTIONS, a NULL semaphore is now reported by the
assertion 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, full
ostest:

ostest_main: Exiting with status 0

sim:nsh builds with no warning. No regression test: the change only
moves the use of the pointer after its assertion, and a NULL semaphore
stops the system with or without it.

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>
@github-actions github-actions Bot added Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small labels Nov 24, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

mps2-an500-citest

  • flash: .text +40 B (+0.0%, 247,280 B / 4,194,304 B, total: 6% used)

mps2-an500-citest-protected

  • flash: .text +40 B (+0.0%, 116,448 B / 4,194,304 B, total: 3% used)

qemu-armv8a

  • Code: .rodata +16 B, .text.nxsem_destroy +24 B (+0.0%, 377,500 B)

qemu-intel64

  • Code: .text +48 B (+0.0%, 8,706,923 B)
  • Data: .rodata +32 B (+0.0%, 109,089 B)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@Shanks0224

Copy link
Copy Markdown
Contributor Author

@GUIDINGLI PTAL

@GUIDINGLI
GUIDINGLI merged commit 0cf5fd5 into apache:master Nov 25, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants