gcc UAF warning in test/perf/singlethread -malloc

When building test/perf/singlethread to use the system allocator, gcc
(Debian 14.2.0-3) correctly sees that we were using the value of a
pointer after it had been passed to the privileged free(), which is UB.

Flip the check and dealloc, so that we query the set of pointers we're
tracking first, using the pointer while the allocation is still live.
This commit is contained in:
Nathaniel Wesley Filardo
2024-09-21 04:48:32 +01:00
committed by Nathaniel Wesley Filardo
parent 19259095c6
commit 416fd39f6a

View File

@@ -34,9 +34,9 @@ void test_alloc_dealloc(size_t count, size_t size, bool write)
{
auto it = set.begin();
void* p = *it;
alloc.dealloc(p, size);
set.erase(it);
SNMALLOC_CHECK(set.find(p) == set.end());
alloc.dealloc(p, size);
}
// alloc 1x objects