0

I have the code as below:

char* Add()
{
    p = new char[10];
    return p;
}

and I use CPPUTEST with the test code as below:

TEST(MyTestGroup, TestAdd_1)
{
    p = Add(); // the above function
    delete p;
}

But the error is: "Allocation/deallocation type mismatch"

I don't know why, please help. Thanks in advance!

ollo
  • 24,797
  • 14
  • 106
  • 155

1 Answers1

3

But the error is: "Allocation/deallocation type mismatch"

That's because you allocate an array, but deallocate a single object.

TEST(MyTestGroup, TestAdd_1)
{
    p = Add(); // the above function
    delete[] p; // <--- Use correct delete for arrays
}
ollo
  • 24,797
  • 14
  • 106
  • 155