Rule Definition
The memory dynamically allocated in a local pointer of a function or method should be released by using "delete" or "free()" before the end of the of the lifetime of the pointer variable, i.e. before the end of said function/method or before a "return" or "throw" statement.
Remediation
Release the memory allocated dynamically before any "return" or "throw" statement or before the end of the function or method.
Violation Code Sample
int func(int num)
{
int* val = new int(0);
std::exception exc;
if(num < 0)
throw exc;
delete val;
return 1;
}
Fixed Code Sample
int func(int num)
{
int* val = new int(0);
std::exception exc;
if(num < 0)
{
delete val;
throw exc;
}
delete val;
return 1;
}
Related Technologies
Technical Criterion
PCI-DSS4-Requirement-6.2.4 - Software engineering techniques or other methods are defined and in use by software development personnel to prevent or mitigate common software attacks and related vulnerabilities
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.