Skip to content

fix: [libpthreadglue] tighten error handling in OS-abstraction layer#364

Merged
sharkwouter merged 1 commit into
pspdev:masterfrom
fjtrujy:fix/libpthreadglue-osal-error-handling
May 12, 2026
Merged

fix: [libpthreadglue] tighten error handling in OS-abstraction layer#364
sharkwouter merged 1 commit into
pspdev:masterfrom
fjtrujy:fix/libpthreadglue-osal-error-handling

Conversation

@fjtrujy
Copy link
Copy Markdown
Member

@fjtrujy fjtrujy commented May 11, 2026

Summary

  • pte_osThreadCreate ignored the return value of sceKernelCreateSema when creating cancelSem, and on the sceKernelCreateThread failure paths it leaked the just-created cancelSem.
  • Reorder so each resource is validated immediately after it is allocated and cleaned up in reverse order on failure.
  • Propagate sceKernelCreateSema failures from pte_osMutexCreate and pte_osSemaphoreCreate as PTE_OS_NO_RESOURCES instead of writing a negative handle to *pHandle as if it were a valid semaphore.

Related

Test plan

  • Build src/libpthreadglue cleanly.
  • Run pthread-embedded test suite on PSP — exercises thread/mutex/sema creation paths and now also the NULL-handle paths from the companion pthread-embedded PR.
  • Smoke-test a sample that creates pthreads.

pte_osThreadCreate previously:
- ignored the return value of sceKernelCreateSema for cancelSem
- on the sceKernelCreateThread failure paths, leaked the cancelSem
  semaphore that had just been created

Reorder so each resource is validated immediately after allocation and
cleaned up in reverse order on failure. Also propagate
sceKernelCreateSema failures from pte_osMutexCreate and
pte_osSemaphoreCreate as PTE_OS_NO_RESOURCES instead of writing a
negative handle to *pHandle as if it were valid.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sharkwouter sharkwouter merged commit e62057d into pspdev:master May 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants