ICU-23353 Fix double-delete in Region::cleanupRegionData#3922
ICU-23353 Fix double-delete in Region::cleanupRegionData#3922hirorogo wants to merge 1 commit intounicode-org:maint/maint-54from
Conversation
|
Could a maintainer please transition the Jira ticket ICU-23353 from New to Accepted? The |
662d250 to
7703e0c
Compare
|
Hooray! The files in the branch are the same across the force-push. 😃 ~ Your Friendly Jira-GitHub PR Checker Bot |
| for (int32_t i = 0 ; i < URGN_LIMIT ; i++ ) { | ||
| if ( availableRegions[i] ) { | ||
| delete availableRegions[i]; | ||
| availableRegions[i] = NULL; |
There was a problem hiding this comment.
Please replace NULL with nullptr everywhere in C++.
There was a problem hiding this comment.
Done — replaced all NULL with nullptr in the changed lines.
| u_cleanup(); | ||
| u_cleanup(); // must not crash |
There was a problem hiding this comment.
Calling u_cleanup() without closing all ICU objects is probably not defined, and calling it in the middle of the large test suite might have unforeseen side effects. Especially if we run tests in parallel.
The intltest test suite calls u_cleanup() at the very end. Does this problem reproduce if we call u_cleanup() twice there?
Otherwise, we might need to spin up a mini test suite just for this.
@aheninger @echeran WDYT?
There was a problem hiding this comment.
Good point — removed the mid-suite u_cleanup() calls entirely. The test now only verifies Region data consistency (getInstance + contains).
The actual double-cleanup crash reproducer is documented in a comment block as a standalone program. This avoids side effects on other ICU services and is safe for parallel test execution.
If you'd prefer a dedicated mini test binary instead, happy to set that up.
|
While working on this fix, I noticed the same pattern (free-without-nullify in cleanup functions) exists in several other places on the 1.
|
eb20233 to
65cc2dd
Compare
|
Hooray! The files in the branch are the same across the force-push. 😃 ~ Your Friendly Jira-GitHub PR Checker Bot |
Set availableRegions[i] to nullptr after deletion in cleanupRegionData() to prevent use-after-free when u_cleanup() is called twice. Also update IntlTestRegion to use nullptr consistently and verify double-cleanup safety. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Checklist
Summary
Region::cleanupRegionData()inregion.cppdeletes/closesavailableRegions[],regionAliases,numericCodeMap, andregionIDMapbut does not nullify the pointers afterward. If cleanup is called multiple times (e.g., via repeatedu_cleanup()calls), the same memory is freed twice, causing a double-delete / use-after-free.Fix: Set each pointer to
NULLimmediately afterdelete/uhash_closeso subsequent calls are safe no-ops.Test plan
TestDoubleCleanupadded toregiontst.cpp: initializes Region data, callsu_cleanup()twice in a row, then verifies Region can be re-initialized and used normally. Without the fix this crashes on the secondu_cleanup().