Skip to content

Commit ef4c628

Browse files
luisleo526claude
andcommitted
test_p2cx_tledger_io: replace the nothrow operator new/delete forms too
The test replaces the global operator new/delete with malloc/free to count allocations, but not the nothrow forms. CommandScratchStore allocates with `new (std::nothrow)`, so under ASan that block came from the sanitizer's own nothrow new and was released by the replaced operator delete's free(): alloc-dealloc-mismatch abort (sanitizers leg of PR #496, rj-20261024t184800-7cdb3a, test_p2cx_tledger_io). Add malloc-backed operator new/new[] (std::nothrow_t) with the same counter, and the matching nothrow operator delete/delete[]. Test only; no src or include change. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent d21ea8d commit ef4c628

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎tests/test_p2cx_tledger_io.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ void operator delete(void* pointer) noexcept { std::free(pointer); }
4646
void operator delete[](void* pointer) noexcept { std::free(pointer); }
4747
void operator delete(void* pointer, std::size_t) noexcept { std::free(pointer); }
4848
void operator delete[](void* pointer, std::size_t) noexcept { std::free(pointer); }
49+
// The nothrow forms must be replaced too: CommandScratchStore allocates with
50+
// `new (std::nothrow)`, and a block from the sanitizer's own nothrow new would
51+
// otherwise be released by the free() above (alloc-dealloc-mismatch).
52+
void* operator new(std::size_t bytes, const std::nothrow_t&) noexcept {
53+
void* result = std::malloc(bytes ? bytes : 1);
54+
if (result && ledger_io::measuring) ++ledger_io::counts.allocations;
55+
return result;
56+
}
57+
void* operator new[](std::size_t bytes, const std::nothrow_t& tag) noexcept {
58+
return ::operator new(bytes, tag);
59+
}
60+
void operator delete(void* pointer, const std::nothrow_t&) noexcept { std::free(pointer); }
61+
void operator delete[](void* pointer, const std::nothrow_t&) noexcept { std::free(pointer); }
4962

5063
extern "C" ssize_t pread(int fd, void* data, std::size_t length, off_t offset) {
5164
if (ledger_io::measuring) ++ledger_io::counts.reads;

0 commit comments

Comments
 (0)