Skip to content

Commit fc52262

Browse files
committed
Free backing storage in small-block PayloadBuffer tests
SmallBlockAllocSimple, SmallBlockAlloc, and SmallBlockAllocFree used placement-new into calloc storage but never destroyed the object or released the block, which Valgrind reported as definitely lost. Tear down with an explicit destructor and free().
1 parent 7e420b4 commit fc52262

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

toolbelt/payload_buffer_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ TEST(BufferTest, SmallBlockAllocSimple) {
105105
// Allocate again and make sure it's the same address.
106106
void *addr2 = PayloadBuffer::Allocate(&pb, 16);
107107
ASSERT_EQ(addr, addr2);
108+
109+
pb->~PayloadBuffer();
110+
free(buffer);
108111
}
109112

110113
TEST(BufferTest, SmallBlockAlloc) {
@@ -137,6 +140,9 @@ TEST(BufferTest, SmallBlockAlloc) {
137140
}
138141
pb->Dump(std::cout);
139142
toolbelt::Hexdump(pb, pb->hwm);
143+
144+
pb->~PayloadBuffer();
145+
free(buffer);
140146
}
141147

142148
TEST(BufferTest, SmallBlockAllocFree) {
@@ -169,6 +175,9 @@ TEST(BufferTest, SmallBlockAllocFree) {
169175
}
170176
pb->Dump(std::cout);
171177
toolbelt::Hexdump(pb, pb->hwm);
178+
179+
pb->~PayloadBuffer();
180+
free(buffer);
172181
}
173182

174183
// This performance test compares the performance of the small block allocator

0 commit comments

Comments
 (0)