2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-06-08 14:23:48 +02:00
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.
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-06-08 14:23:48 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-06-08 14:23:48 +02:00
----
char *cp = new char[10];
// ...
delete cp; // Noncompliant
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-06-08 14:23:48 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-06-08 14:23:48 +02:00
----
char *cp = new char[10];
// ...
delete[] cp;
----
ifdef::env-github,rspecator-view[]
2021-06-08 15:52:13 +02:00
'''
2021-06-08 14:23:48 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== duplicates: S1232
=== on 10 Mar 2016, 22:29:47 Evgeny Mandrikov wrote:
Looks like duplicate of RSPEC-1232
=== on 11 Mar 2016, 08:31:55 Ann Campbell wrote:
Thanks [~evgeny.mandrikov], you're right.
2021-06-08 14:23:48 +02:00
endif::env-github,rspecator-view[]