Skip to content

fix(libc): release unpublished locale copies - #19884

Closed
DonRyuzaki wants to merge 1 commit into
boykopovar:mainfrom
DonRyuzaki:codex/locale-copy-cleanup-20261114
Closed

DonRyuzaki wants to merge 1 commit into
boykopovar:mainfrom
DonRyuzaki:codex/locale-copy-cleanup-20261114

Conversation

@DonRyuzaki

Copy link
Copy Markdown
Contributor

What

Release the unpublished outer _Locimp object when its facet-vector allocation throws. This matches the exceptional object cleanup documented by the module-derived merged #16165. Attempt scalar delete once, preserve the primary allocator exception, and leave ordinary false-return deletion outside that catch. This does not add guarantees for arbitrary facet-retain callbacks after partial construction.

Tested

Linux, Ubuntu 24.04 under WSL2, GCC 13.3, Release. Base f9854b5a4b80a661ad6a5638565fc6d72a2f0a1a, head 24c0d4d0105b93f6d5d570d79571507216f1ce98, tree 020f14c5380e5ed60ce9a712b31b3be853e22d23.

  • Full runtime: cmake --build build --target libs guest_sce_v2_locimp_references_tests --parallel 8 passes on this exact head.
  • ctest --test-dir build --no-tests=error --output-on-failure -R '^guest_sce_v2_locimp_references$' passes, zero skips.
  • The existing guest_sce_v2_locimp_references suite passes. Baseline fixtures qualify vector allocation only after the outer 48-byte object exists, then reproduce its missing release. The correction covers typed allocator failure, release-then-throw cleanup without replacing the primary or retrying free, unchanged source facet counts, existing null-return behavior, and subsequent lock acquisition from another thread.
  • Local negative control 85b6bda6d8492e0f71061bf0e9c89b043408ea45 applies only the changed fixtures to the unchanged base; no production correction is copied into that control.
  • Windows GCC 15.2 Release object compilation passes for 1 fixture source(s). This is compile-only evidence, not Windows linking or runtime execution.
  • Configured with BUILD_TESTING=ON, FT_ENABLE_ERROR_STRINGS=OFF, CMAKE_LINK_DEPENDS_NO_SHARED=ON. Conventions and literal git diff --check pass.
  • The full checker left three older conflicting branches unverified: feat(libc): add std::__sce_v2::_Random_device, _Fiopen and setw #9526, feat(libc): wire the codecvt<wchar_t,char> facet vtable #11172 and feat(libSceLibcInternal): construct the moneypunct facet and answer its members #18135. Their complete LocaleSupport.cpp diffs were manually read at exact heads, with source/patch hashes retained. They add setw handling, codecvt adapters and moneypunct methods respectively; none owns this _New_Locimp cleanup. No functional dependency was found. This is a manual assessment supplementing the fail-closed checker, not a clean automated result or a claim that those older branches merge with current main.
  • No game, GPU or console-hardware execution is claimed. Linux runtime results and Windows compile-only results are distinct.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@JJenkx

JJenkx commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 24c0d4d010, merged onto main 6f6d066c7e (abfca50089, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_sce_v2_locimp_references passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions github-actions Bot added the libc label Nov 14, 2026
@github-actions

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 9526 core/libs/prx/libc/src/LocaleSupport.cpp
PR 11172 core/libs/prx/libc/src/LocaleSupport.cpp
PR 18135 core/libs/prx/libc/src/LocaleSupport.cpp

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 24c0d4d010:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_sce_v2_locimp_references_tests built cleanly.
  • CTest (guest_sce_v2_locimp_references):
    1/1 Test #967: guest_sce_v2_locimp_references ...   Passed    0.00 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/src/LocaleSupport.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #967: guest_sce_v2_locimp_references ...***Failed    0.00 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • LocaleSupport.cpp: _ZNSt8__sce_v26locale7_Locimp11_New_LocimpERKS1__nid_postfix: Verified exceptional cleanup safely deallocates the unpublished self instance via _ZdlPv_nid_postfix when CopySceV2Facets throws during facet-vector allocation, preventing memory leaks.
    • LocaleSupport.cpp: _ZNSt8__sce_v26locale7_Locimp11_New_LocimpERKS1__nid_postfix: Verified that nested exception handling wraps _ZdlPv_nid_postfix(self) in a try-catch block, ensuring any secondary exception during scalar deallocation does not mask or replace the rethrown primary allocator exception.
    • LocaleSupport.cpp: _ZNSt8__sce_v26locale7_Locimp11_New_LocimpERKS1__nid_postfix: Verified that the normal allocation failure path (CopySceV2Facets returning false) remains preserved outside the catch block, executing _ZdlPv_nid_postfix(self) followed by _ZNSt8__sce_v211_Xbad_allocEv_nid_postfix().
    • LocaleSupport.cpp: CopySceV2Facets: Verified that g_sceV2LocimpMutex held by std::lock_guard is reliably unlocked via RAII stack unwinding when an allocation exception throws, preventing deadlock on subsequent access from other threads.
    • GuestSceV2LocimpReferences.cpp: main: Verified unit test coverage exercises both non-throwing and throwing deallocation (throwFree in {false, true}), verifying exception propagation, exact deallocation targeting gLastObject, and invariant source facet counts.
    • LocaleSupport.cpp & GuestSceV2LocimpReferences.cpp: Verified AGENTS.md rule compliance, confirming no comments were introduced into code, conventional commit formatting was followed, and no unauthorized files were added.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@DonRyuzaki I am closing this as padding. It releases libc locale copies that were never published to the caller, a path no title reaches, and the same kind of change has been sent for many libraries, so we are not taking this series. If a game hits a real leak, a PR for that case with the title and the run that shows it is welcome.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants