Repository navigation
Fix ASan alloc-dealloc mismatch in nothrow new test hooks - #103
Merged
Merged
Conversation
The LoadData OOM tests still fail SimpleIni's new (nothrow) through a shared policy, but the success path now uses throwing ::operator new so ASan no longer reports malloc vs operator delete on GoogleTest/libstdc++ temporary buffers. Co-authored-by: Brodie Thiesfield <brofield@users.noreply.github.com>
Add tests for first-load parse-buffer failure, LoadFile read-buffer failure, LoadFile-then-LoadData parse-buffer failure, SetValue CopyString new failure, and file-comment CopyString cleanup. The existing incremental leak test no longer starts with a file comment, so it actually fails in AddEntry. Co-authored-by: Brodie Thiesfield <brofield@users.noreply.github.com>
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.
Summary
The Linux allocation-failure hooks in
tests/ts-regressions.cppreplaced nothrowoperator new/new[]with__wrap_malloc. That is required: SimpleIni allocates withnew (std::nothrow), which libstdc++ implements in a DSO, so--wrap=mallocnever sees those calls.Returning
mallocmemory fromoperator newmade AddressSanitizer abort before any test body.testing::TestSuite::Run()callsstd::stable_sort, libstdc++get_temporary_bufferuses::operator new(n, std::nothrow), and the matching free is sized::operator delete. ASan reportsmalloc vs operator delete.Keep the same fail-after-N / fail-small policy for both
__wrap_mallocand the nothrownewreplacements. On success, nothrownewnow delegates to throwing::operator newsodelete[]matches. Do not call__wrap_mallocfromoperator new, or the budget would decrement twice.Also cover every
SI_NOMEMallocation site that the default Linux build can reach:LoadDataparse buffer (new SI_CHAR[uLen+1])LoadFileread buffer (new char[uSize+1])LoadFileread buffer succeeds, thenLoadDataparse buffer failsCopyStringviaSetValue(newreturns nullptr)LoadDatafile-commentCopyStringfailureLoadDataAddEntry/CopyStringfailure (existing leak test no longer starts with a file comment, so it actually hitsAddEntry)Not covered, on purpose: ICU
UCharPathToUtf8(not in the default build) andstd::mapbad_alloc(not turned intoSI_NOMEM).Validation
alloc_dealloc_mismatch=1anddetect_leaks=1: 290 tests passLoadDataRegressionandLoadFileRegressionOOM cases pass in both builds