[2/4] gdb: clear internalvar on destruction

Message ID 20250310151211.2708331-3-simon.marchi@polymtl.ca
State New
Headers
Series Modernize and fix leaks around internal_function |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Simon Marchi March 10, 2025, 3:10 p.m. UTC
  From: Simon Marchi <simon.marchi@efficios.com>

The data associated to an internalvar is destroyed when changing the
kind of the internalvar, but not when it is destroyed.  Fix that by
calling clear_internalvar in ~internalvar.

A move constructor becomes needed to avoid freeing things multiple times
when internalvars are moved (and if we forget it, clang helpfully gives
us a -Wdeprecated-copy-with-user-provided-dtor warning).

Change-Id: I427718569208fd955ea25e94d341dde356725033
---
 gdb/value.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Patch

diff --git a/gdb/value.c b/gdb/value.c
index 18c9f7494674..8b8b5c8f4de1 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1872,6 +1872,19 @@  struct internalvar
     : name (std::move (name))
   {}
 
+  internalvar (internalvar &&other)
+    : name (std::move(other.name)),
+      kind (other.kind),
+      u (other.u)
+  {
+    other.kind = INTERNALVAR_VOID;
+  }
+
+  ~internalvar ()
+  {
+    clear_internalvar (this);
+  }
+
   std::string name;
 
   /* We support various different kinds of content of an internal variable.