]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix a compile time memory leak in finish_static_assert
authorJakub Jelinek <jakub@redhat.com>
Wed, 29 Nov 2023 08:19:02 +0000 (09:19 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 29 Nov 2023 08:19:02 +0000 (09:19 +0100)
On Tue, Nov 28, 2023 at 11:31:48AM -0500, Jason Merrill wrote:
> Jonathan pointed out elsewhere that this gets leaked if error return
> prevents us from getting to the XDELETEVEC.

As there is a single error return in which it can leak, I've just added
a XDELETEVEC (buf); statement to that path rather than introducing some
RAII solution.

2023-11-29  Jakub Jelinek  <jakub@redhat.com>

* semantics.cc (finish_static_assert): Free buf on error return.

gcc/cp/semantics.cc

index 3bf586453dcbb30eee9d8c0a095734cb4cd31400..d30a3f99c040e36258f54563d3f22979a003a5be 100644 (file)
@@ -11582,6 +11582,7 @@ finish_static_assert (tree condition, tree message, location_t location,
                          error_at (location,
                                    "%<static_assert%> message %<data()[%d]%> "
                                    "must be a constant expression", i);
+                         XDELETEVEC (buf);
                          return;
                        }
                      if (msg == NULL)