google / googletest

GoogleTest - Google Testing and Mocking Framework

Home Page:https://google.github.io/googletest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Double free or corruption detected in first parameterized test

eduvfalc opened this issue · comments

Describe the issue

I have parameterized some tests for a particular test fixture. The input parameters are pairs of ints. Every first test of the parameterized test suite executes successfully but flags double free or corruption (out). I find it odd that it happens in the first test only, regardless of the input values. All the other tests do not show the same issue.

Steps to reproduce the problem

Test fixture class:

class TestZeroPadding : public ::testing::TestWithParam<std::pair<int, int>>
{
protected:
    std::shared_ptr<DSPUtils<Complex, std::vector>> dsp_utils = std::make_shared<DSPUtils<Complex, std::vector>>();
};

Note: DSPUtils<Complex, std::vector> and std::make_shared<DSPUtils<Complex, std::vector>> are custom template classes defined in here.

Value-parameterized test:

TEST_P(TestZeroPadding, SignalsArePowersOf2)
{
    const int            signal_size = GetParam().first;
    std::vector<Complex> test_signal(signal_size);
    for (int i = 0; i <= signal_size; ++i)
        test_signal[i] = Complex(i, 0);
    const auto next_pow_2 = GetParam().second;

    dsp_utils->zero_padding(test_signal);

    EXPECT_EQ(test_signal.size(), next_pow_2);
}

Value-parameterized test suite instantiation:

INSTANTIATE_TEST_CASE_P(SignalsArePowersOf2,
                        TestZeroPadding,
                        ::testing::Values(std::make_pair(5, 8),
                                          std::make_pair(9, 16),
                                          std::make_pair(590, 1024),
                                          std::make_pair(3000, 4096)));

What version of GoogleTest are you using?

v1.14.0 (latest).

What operating system and version are you using?

Linux Ubuntu 22.04 Jammy

What compiler and version are you using?

gcc/g++ 10.5.0

What build system are you using?

CMake 3.22.1

Additional context

No response

How did you resolve this?
I believe I am facing a similar issue.
I am instantiating a
class MyTest : public testing::TestWithParam<size_t>
with
INSTANTIATE_TEST_SUITE_P(Prefix, MyTest, testing::Values(1U));
and get
double free or corruption (out)
without having any tests run

I noticed that it was happening with a single test data pair I was using as input to the test, but I believe this should be reopened for better clarification.

Turns out I have been building my own libraries with -D_GLIBCXX_DEBUG and building googletest without this define flag.
Compiling and linking my own libraries and googletest without -D_GLIBCXX_DEBUG seems to have solved the issue for me.