1

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;
    }
alk
  • 69,737
  • 10
  • 105
  • 255
Mati
  • 753
  • 4
  • 20
  • 1
    I think they are probably real leaks, in the sense that the `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. – John Bollinger Dec 24 '20 at 15:00
  • 1
    I doubt that those are real (dynamic) application-wide leaks. Most Unittestframeworks have to apply several static global workarounds to allow quasi-reflection for your implemented tests. – Secundi Dec 24 '20 at 15:07
  • That's not the Valgrind output. CppUnit or CLion has munged it. Secondly, that looks like a custom placement new. We would need to know more about it in order to say more. – Paul Floyd Dec 25 '20 at 08:26

0 Answers0