Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 1/3] gdbserver: make arch and osabi names gdb::unique_xmalloc_ptr<char>
Date: Sun,  6 Oct 2024 19:37:05 +0100	[thread overview]
Message-ID: <cd24e42eeb1e4a51f62f3c80a25a607533effcc2.1728239729.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1728239729.git.aburgess@redhat.com>

Convert target_desc::arch and target_desc::osabi from 'const char*' to
gdb::unique_xmalloc_ptr<char>.  This also allows us to remove the user
defined ~target_desc destructor.

I doubt it ever actually occurred, but in theory at least, there was a
memory leak in set_tdesc_architecture and set_tdesc_osabi where the
member variables were assigned without freeing any previous
value... but I suspect that usually these fields are only set once.

There should be no user visible changes after this commit.
---
 gdbserver/tdesc.cc | 16 +++++-----------
 gdbserver/tdesc.h  |  6 ++----
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/gdbserver/tdesc.cc b/gdbserver/tdesc.cc
index 3265793da96..7f11120c318 100644
--- a/gdbserver/tdesc.cc
+++ b/gdbserver/tdesc.cc
@@ -20,12 +20,6 @@
 
 #ifndef IN_PROCESS_AGENT
 
-target_desc::~target_desc ()
-{
-  xfree ((char *) arch);
-  xfree ((char *) osabi);
-}
-
 bool target_desc::operator== (const target_desc &other) const
 {
   if (reg_defs != other.reg_defs)
@@ -162,7 +156,7 @@ tdesc_compatible_info_arch_name (const tdesc_compatible_info_up &c_info)
 const char *
 tdesc_architecture_name (const struct target_desc *target_desc)
 {
-  return target_desc->arch;
+  return target_desc->arch.get ();
 }
 
 /* See gdbsupport/tdesc.h.  */
@@ -171,7 +165,7 @@ void
 set_tdesc_architecture (struct target_desc *target_desc,
 			const char *name)
 {
-  target_desc->arch = xstrdup (name);
+  target_desc->arch = make_unique_xstrdup (name);
 }
 
 /* See gdbsupport/tdesc.h.  */
@@ -179,7 +173,7 @@ set_tdesc_architecture (struct target_desc *target_desc,
 const char *
 tdesc_osabi_name (const struct target_desc *target_desc)
 {
-  return target_desc->osabi;
+  return target_desc->osabi.get ();
 }
 
 /* See gdbsupport/tdesc.h.  */
@@ -187,7 +181,7 @@ tdesc_osabi_name (const struct target_desc *target_desc)
 void
 set_tdesc_osabi (struct target_desc *target_desc, const char *name)
 {
-  target_desc->osabi = xstrdup (name);
+  target_desc->osabi = make_unique_xstrdup (name);
 }
 
 /* See gdbsupport/tdesc.h.  */
@@ -198,7 +192,7 @@ tdesc_get_features_xml (const target_desc *tdesc)
   /* Either .xmltarget or .features is not NULL.  */
   gdb_assert (tdesc->xmltarget != NULL
 	      || (!tdesc->features.empty ()
-		  && tdesc->arch != NULL));
+		  && tdesc_architecture_name (tdesc) != nullptr));
 
   if (tdesc->xmltarget == NULL)
     {
diff --git a/gdbserver/tdesc.h b/gdbserver/tdesc.h
index 534b8b000f5..6fc37d038bc 100644
--- a/gdbserver/tdesc.h
+++ b/gdbserver/tdesc.h
@@ -54,18 +54,16 @@ struct target_desc final : tdesc_element
   mutable const char *xmltarget = NULL;
 
   /* The value of <architecture> element in the XML, replying GDB.  */
-  const char *arch = NULL;
+  gdb::unique_xmalloc_ptr<char> arch = nullptr;
 
   /* The value of <osabi> element in the XML, replying GDB.  */
-  const char *osabi = NULL;
+  gdb::unique_xmalloc_ptr<char> osabi = nullptr;
 
 public:
   target_desc ()
     : registers_size (0)
   {}
 
-  ~target_desc ();
-
   bool operator== (const target_desc &other) const;
 
   bool operator!= (const target_desc &other) const
-- 
2.25.4


  reply	other threads:[~2024-10-06 18:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-06 18:37 [PATCH 0/3] Set osabi in remote target descriptions Andrew Burgess
2024-10-06 18:37 ` Andrew Burgess [this message]
2024-10-07 17:00   ` [PATCH 1/3] gdbserver: make arch and osabi names gdb::unique_xmalloc_ptr<char> Tom Tromey
2024-10-08 19:02   ` Simon Marchi
2024-10-09 11:07     ` Andrew Burgess
2024-10-09 11:45       ` Simon Marchi
2024-10-09 12:17         ` Andrew Burgess
2024-10-09 15:35           ` Simon Marchi
2024-10-09 15:50             ` Andrew Burgess
2024-10-06 18:37 ` [PATCH 2/3] gdb: make use of set_tdesc_osabi overload in features/ files Andrew Burgess
2024-10-07 17:00   ` Tom Tromey
2024-10-08 19:12   ` Simon Marchi
2024-10-09 11:08     ` Andrew Burgess
2024-10-09 11:48       ` Simon Marchi
2024-10-09 12:04         ` Andrew Burgess
2024-10-06 18:37 ` [PATCH 3/3] gdbserver: pass osabi to GDB in target description Andrew Burgess
2024-10-07  9:38   ` Luis Machado
2024-10-07 17:00   ` Tom Tromey
2024-10-08 17:11 ` [PATCH 0/5] Set osabi in remote target descriptions Andrew Burgess
2024-10-08 17:11   ` [PATCH 1/5] gdbserver: make arch and osabi names gdb::unique_xmalloc_ptr<char> Andrew Burgess
2024-10-10 13:37     ` Simon Marchi
2024-10-10 15:31       ` Andrew Burgess
2024-10-08 17:11   ` [PATCH 2/5] gdb: make use of set_tdesc_osabi overload in features/ files Andrew Burgess
2024-10-08 17:11   ` [PATCH 3/5] gdb: split osabi support between gdb/ and gdbsupport/ directories Andrew Burgess
2024-10-09  7:12     ` Luis Machado
2024-10-10 13:47     ` Simon Marchi
2024-10-08 17:11   ` [PATCH 4/5] gdb/gdbserver: change shared set_tdesc_osabi to take gdb_osabi Andrew Burgess
2024-10-09  7:12     ` Luis Machado
2024-10-10 15:23     ` Simon Marchi
2024-10-08 17:11   ` [PATCH 5/5] gdbserver: pass osabi to GDB in target description Andrew Burgess
2024-10-09  7:14     ` Luis Machado
2024-10-10 15:56     ` Simon Marchi
2024-10-10 20:19     ` Mark Wielaard
2024-10-11  8:31       ` Andrew Burgess
2024-10-10 15:57   ` [PATCH 0/5] Set osabi in remote target descriptions Simon Marchi
2024-10-10 16:41     ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd24e42eeb1e4a51f62f3c80a25a607533effcc2.1728239729.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox