rspec/rules/S3530/cfamily/rule.adoc

32 lines
585 B
Plaintext
Raw Normal View History

Memory that is allocated with ``++new T[n]++`` _must_ be freed with ``++delete[]++``. Leave out the ``++[]++``, and the likely result is heap corruption or, as a best-case scenario, premature program termination.
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,cpp]
----
char *cp = new char[10];
// ...
delete cp; // Noncompliant
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,cpp]
----
char *cp = new char[10];
// ...
delete[] cp;
----
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]