public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdbserver: add client_state destructor
@ 2024-05-03 12:29 Guinevere Larsen
  2024-05-03 13:21 ` Keith Seitz
  2024-05-03 13:31 ` Tom Tromey
  0 siblings, 2 replies; 8+ messages in thread
From: Guinevere Larsen @ 2024-05-03 12:29 UTC (permalink / raw)
  To: gdb-patches; +Cc: Guinevere Larsen

the struct client_state in gdbserver allocated memory dynamically in its
constructor, but it never deallocates it. This was pointed out by a
static analyzer that ran on the repo. While I think this was done
because client_states are never destructed, I think it would still be
good to have a destructor in case that ever changes, either on purpose
or by accident.

Tested with native-gdbserver on x86_64.
---
 gdbserver/server.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gdbserver/server.h b/gdbserver/server.h
index 0074818c6df..256294b0052 100644
--- a/gdbserver/server.h
+++ b/gdbserver/server.h
@@ -133,6 +133,12 @@ struct client_state
     own_buf ((char *) xmalloc (PBUFSIZ + 1)) 
   {}
 
+  ~client_state ()
+  {
+    if (own_buf != nullptr)
+      xfree (own_buf);
+  }
+
   /* The thread set with an `Hc' packet.  `Hc' is deprecated in favor of
      `vCont'.  Note the multi-process extensions made `vCont' a
      requirement, so `Hc pPID.TID' is pretty much undefined.  So
-- 
2.44.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-05-20 16:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-03 12:29 [PATCH] gdbserver: add client_state destructor Guinevere Larsen
2024-05-03 13:21 ` Keith Seitz
2024-05-03 13:31 ` Tom Tromey
2024-05-03 13:33   ` Guinevere Larsen
2024-05-03 15:17     ` Tom Tromey
2024-05-03 16:14       ` Pedro Alves
2024-05-03 17:00         ` Simon Marchi
2024-05-20 16:54           ` Guinevere Larsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).