TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
ASML C Coding Standard
Search

Rule:  6.2.4.bChecked automatically with code checker

Synopsis:Memory operations shall be symmetric; allocation and de-allocation shall take place in the same scope where the allocated variable is defined.
Language:C
Severity Level:4
Category:Concepts


Description:

Justification

Applying symmetric allocation and de-allocation decreases the risk for memory leaks significantly.

Example

int function()
{
   int result = OK;

   object_struct *struct1 = NULL;   /* Locally defined variable */
   result = full_create(..., &struct1);
 
   /* Use struct1 here */

   result = full_destroy(..., &struct1);

   return result;
}

Exception

Functions are allowed to return allocated memory through an 'out' parameter and leave the de-allocation to the caller. It must be clearly indicated in the interface documentation when de-allocation by the caller is required.