Skip to content

Commit 6a97831

Browse files
committed
Improved leak logging
1 parent 612bcbd commit 6a97831

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/ptrie/ptrie.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ inline uchar* new_uchar2(std::size_t size, const std::string& src [[maybe_unused
100100
if (alive.find(res) != alive.end()) {
101101
std::abort();
102102
}
103-
alive[res] = std::to_string(size) + ' ' + src + ':' + std::to_string(line);
103+
alive[res] = std::to_string(size) + " bytes allocated at " + src + ':' + std::to_string(line);
104104
#endif // PTRIE_MEMORY_LOGGING
105105
return res;
106106
}

test/set.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ TEST_CASE("Pseudo Rand1")
7979
}
8080
#ifdef PTRIE_MEMORY_LOGGING
8181
auto& alive = ptrie::get_alive();
82-
if (!alive.empty()) {
83-
std::clog << "Memory leaks:\n";
84-
for (auto& [ptr, src] : alive)
85-
std::clog << ptr << " " << src << '\n';
86-
}
82+
auto os = std::ostringstream{};
83+
for (const auto& [_, src] : alive)
84+
os << "Leaked " << src << '\n';
85+
CHECK_MESSAGE(alive.empty(), "Detected memory leaks:\n", os.str());
8786
#endif // PTRIE_MEMORY_LOGGING
8887
}
8988

0 commit comments

Comments
 (0)