AutosarC++17_03-A18.5.3¶
The form of delete operator shall match the form of new operator used to allocate the memory
Required inputs: IR, StaticSemanticAnalysis
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Plain and array forms of new and delete operators must not be mixed. If new or new[] operator was used to allocate the memory, then respectively delete or delete[] operator is supposed to be used to deallocate it.
Example
// $Id: A18-5-3.cpp 271687 2017-03-23 08:57:35Z piotr.tanski $
#include <cstdint>
void fn1() {
std::int32_t *array =
new std::int32_t[10]; // new[] operator used to allocate the
// memory for an array
// ...
delete array; // Non-compliant - delete[] operator 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 - delete operator 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 [8]: 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¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
maximum_number_of_threads¶
maximum_number_of_threads : int = 0
resources¶
resources : set[str] = {'C++ArrayHeapMemory', 'C++HeapMemory'}
witness_paths¶
witness_paths : bool = True