AutosarC++19_03-A18.5.3

The form of the delete expression shall match the form of the new expression used to allocate the memory

Required inputs: IR, StaticSemanticAnalysis

Rationale

Plain and array forms of new and delete expressions must not be mixed. If an array was allocated using a new expression, then an array delete expression must be used to deallocate it and vice versa.

Example
// $Id: A18-5-3.cpp 316977 2018-04-20 12:37:31Z christof.meerwald $
    #include <cstdint>

    void Fn1()
    {
        std::int32_t* array =
            new std::int32_t[10];     // new expression used to allocate an
                                      // array object
         // ...
         delete array;   // Non-compliant - array delete expression supposed
                         // to be used
    }
    void Fn2()
    {
        std::int32_t* object = new std::int32_t{0};      // new operator used to
                                                         // allocate the memory for an
                                                         // integer type
         // ...
         delete[] object;    // Non-compliant - non-array delete expression supposed
                             // to be used
    }
    void Fn3()
    {
        std::int32_t* object = new std::int32_t{0};
          std::int32_t* array = new std::int32_t[10];
          // ...
          delete[] array; // Compliant
          delete object;   // Compliant
    }
See Also
  • HIC++ v4.0 [9]: 5.3.3 Ensure that the form of delete matches the form of new used to allocate the memory.

Possible Messages

Key

Text

Severity

Disabled

possible_wrong_release

Resource possibly released using wrong function (allocation used {node0})

None

False

wrong_release

Resource released using wrong function (allocation used {node0})

None

False

Options

maximum_number_of_threads

maximum_number_of_threads : int = 0

This option determines how many threads are used during computation of this rule at most. With 0, the maximum number of threads is automatically determined with a heuristic that considers the number of available CPU cores as well as the available memory.
 

resources

resources : set[str] = {'C++ArrayHeapMemory', 'C++HeapMemory'}

Set of resources to be checked (selection of rules in the Resources group).
 

witness_paths

witness_paths : bool = True

Whether witness paths should be determined and included in the issue.