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;
    }
3
  • 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. Commented Dec 24, 2020 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. Commented Dec 24, 2020 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. Commented Dec 25, 2020 at 8:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.