0

Have following code, but CppCheck(1.68) detects only "style" error.

AbstractTelegram *TelegramFactory::CreateGetWigWagParameterTelegram(BYTE     Address_i, BYTE SubAddress_i, BYTE Tag_i)
{
   SignDataWigWag *pWigWag = new SignDataWigWag();

   return new SendTelegram(SubAddress_i, Tag_i, Telegram::GET_WIG_WAG,NULL,0);
}

Output:

Variable 'pWigWag' is assigned a value that is never used.
Variable 'pWigWag' is assigned a value that is never used.

Any options to tune?

blackhearted
  • 37
  • 2
  • 5

2 Answers2

3

I am a Cppcheck developer.

Actually.. we can't see that there is definitely a memory leak in that code.

There are classes that has automatic memory management.

Imagine for example that the SignDataWigWag constructor has such code:

SignDataWigWag::SignDataWigWag() {
    instances.push_back(this);
}

then it can be deleted later by using for instance:

void deleteAllInstances() {
    while (!instances.empty()) {
        delete instances.back();
        instances.pop_back();
    }
}

This is not unusual. Some popular class libraries has lots of classes with some kind of memory management so manual delete is not needed..

Daniel Marjamäki
  • 2,907
  • 15
  • 16
  • there used to be an option to tune this. but as far as I know you can't tune this currently. maybe there will be an option to tune this better someday. – Daniel Marjamäki Jul 14 '15 at 15:23
0

cppcheck is essentially only a style-checker (and like other tools which incorporate the developer's notion of "good style", its usefulness depends on various factors).

There are suitable tools for detecting memory leaks (such as valgrind); cppcheck is not one of those. Of course, you will find differing opinions on which are the best tools, and even on what a tool is suitable for, e.g., a blog entry *Valgrind is NOT a leak checker *

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105