It seems that running valgrind when using cpputest library causes memory leaks errors. I use CLion + WSL (GCC + Valgrind). Every line containing TEST() macro is listed in leaks raport.
error: Failure in TEST(UT_Iterator, NullCases)
Memory leak(s) found.
Alloc num (5) Leak size: 48 Allocated at: /mnt/c/CLionProjects/spi-emulator/unit_test/IteratorTests.cpp and line: 14. Type: "new"
Memory: <0x4daa520> Content:
0000: 30 02 14 00 00 00 00 00 00 00 00 00 00 00 00 00 |0...............|
0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
Total number of leaks: 1
I don't think they are real leaks (do they?). When you expand macro you can see something similar to:
virtual Utest *createTest() override {
return new(
"_file_name_", 14)TEST_UT_Iterator_NullCases_Test;
}
createTest()function returns a pointer to an allocated object, and those objects are not getting freed before the test suite terminates. I am not much familiar with CppUTest, however, to judge whether there is something you're supposed to do to avoid the issue. It is probably ignorable, except inasmuch as it makes it harder to judge whether the code under test has its own leaks.