SCA Does Not Recognize Memory Deallocation Function (C )

SCA Version = 17.10

SCA recognizes the following function as one that allocates dynamic memory:

int* newInt()

{

  return new int(0);

}

SCA recognizes the following function as one that deallocates dynamic memory:

void deleteInt(int* p)

{

  delete p;

}

However, SCA **does not** recognize the following function as one that deallocates dynamic memory:

void deleteInt0(int*& p)

{

  delete p;

  p = NULL; // Want to avoid dangling pointer.

}

I have determined that the use of '&' in the declaration of deleteInt0() causes SCA to not recognize that memory is decallocated.

I have tried to create a custom alias rule to get SCA to recognize this deallocation function. I have tried the following patterns, none of which work:

<Pattern>deleteInt0</Pattern>

<Pattern>deleteInt0(int*&amp;)</Pattern>

As a side note, when catching exceptions in the following example try/catch blocks, SCA claims that the exception object is an instance of "Poor Style: Variable Never Used":

try

{

  // do stuff

}

catch (const std::exception& e)

{

  std::cout << "ERROR " << e.what() << std:;endl;

}

If I rewrite that catch block as:

catch (const std::exception e)

{

  std::cout << "ERROR " << e.what() << std:;endl;

}

then SCA **does not** flag the exception as a variable that is not used.

I prefer catching exceptions by reference to avoid unnecessary copy constructor calls and possible object slicing.

Any one have any ideas as to how I can resolve these false instances of of errors?

Thanks,

K. Banerjee

 

Tags: