The cpp-check error is: error mismatchAllocDealloc false Mismatching allocation and deallocation: val2
What should I do to fix this error?
void MainWindow::ParseDemo(char *pBuf)
{
char* val2 = new char[256];
for (int i = 0; i < 254; i++)
{
val2[i] = pBuf[i+305];
}
val2[254] = 0; // 0-Termination
QString sunit(val2);
DoStuff(sunit);
delete val2;
// ...
}
error mismatchAllocDealloc false Mismatching allocation and deallocation: val2
new and new [] need to be used in a consistent manner with delete and delete [], that's why cppcheck complains.
What should I do to fix this error?
Write delete [] val2;, that should fix it.
BTW, that's not indicating a memory leak directly, but it could become one easily, because it's basically undefined behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With