Closed alexandremgo closed 4 years ago
Hi Alexandre, sorry for late replay, was very tired last days.
Actually this is not a real leak. It's just an unexpected side effect of the test failure. We have the same problem with a few other tests as well.
The problem is caused by CppUTest behavior. When STRCMP_EQUAL (or any other check) fails, it performs a long jump (as you can see from backtrace BTW) and thus skips all local destructors. In our case, EndpointURI destructor is not called. Then it, however, it invokes test group destructor. In our case, it includes HeapAllocator destructor. And in turn, HeapAllocator notices unfreed allocations and reports a leak.
One workaround is to make HeapAllocator global, like it's done in most other tests:
diff --git a/src/tests/roc_address/test_endpoint_uri.cpp b/src/tests/roc_address/test_endpoint_uri.cpp
index acf57bb6..9de95099 100644
--- a/src/tests/roc_address/test_endpoint_uri.cpp
+++ b/src/tests/roc_address/test_endpoint_uri.cpp
@@ -15,9 +15,13 @@
namespace roc {
namespace address {
-TEST_GROUP(endpoint_uri) {
- core::HeapAllocator allocator;
-};
+namespace {
+
+core::HeapAllocator allocator;
+
+} // namespace
+
+TEST_GROUP(endpoint_uri) {};
TEST(endpoint_uri, empty) {
EndpointURI u(allocator);
In this case, HeapAllocator destructor would be called later, after main() returns. But it wont happen because our main() calls fast_exit() if a test fails. This is done intentionally to avoid calling global destructors because of this long jump problem.
A more correct fix would be to force CppUTest to use C++ exceptions instead of long jumps. I saw something about exceptions in their docs, but didn't try it. However, maybe it's not a good idea too because we're not using exceptions and our code is not exception safe, so it can cause other mysterious errors in future :)
Making the HeapAllocator global worked indeed, thanks for the explanation!
Resolved by 0066875333d834507751d898a2bbfa28a169a9d2
Hey! It seems that in some cases, our Ragel parsers create a memory leak. To reproduce, if we add for example " test" to the string being parsed ("rtsp://host:123/path?query test"):
https://github.com/roc-project/roc/blob/bc364daf9f77c83706354c19c139b111414a1a0d/src/tests/roc_address/test_endpoint_uri.cpp#L89-L102
The following error appears: