rspec/rules/S3530/cfamily/rule.adoc

30 lines
559 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
----
char *cp = new char[10];
// ...
delete cp; // Noncompliant
----
== Compliant Solution
----
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[]