public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Use unique_xmalloc_ptr in interp
@ 2022-06-22 19:50 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-06-22 19:50 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3af607d998587de460b9e29996b1d43fa40a76b0

commit 3af607d998587de460b9e29996b1d43fa40a76b0
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri Jun 17 09:31:44 2022 -0600

    Use unique_xmalloc_ptr in interp
    
    This changes interp::m_name to be a unique_xmalloc_ptr, removing some
    manual memory management.  It also cleans up the initialization of the
    'inited' member, and moves the 'private:' and 'public:' keywords to
    their proper spots.

Diff:
---
 gdb/interps.c |  4 +---
 gdb/interps.h | 10 +++++-----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/gdb/interps.c b/gdb/interps.c
index 44002ff2cb5..0c440e78685 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -79,14 +79,12 @@ static struct interp *interp_lookup_existing (struct ui *ui,
 					      const char *name);
 
 interp::interp (const char *name)
-  : m_name (xstrdup (name))
+  : m_name (make_unique_xstrdup (name))
 {
-  this->inited = false;
 }
 
 interp::~interp ()
 {
-  xfree (m_name);
 }
 
 /* An interpreter factory.  Maps an interpreter name to the factory
diff --git a/gdb/interps.h b/gdb/interps.h
index 330c1ba6615..e393b08c962 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -78,20 +78,20 @@ public:
 
   const char *name () const
   {
-    return m_name;
+    return m_name.get ();
   }
 
-  /* This is the name in "-i=" and "set interpreter".  */
 private:
-  char *m_name;
+  /* This is the name in "-i=" and "set interpreter".  */
+  gdb::unique_xmalloc_ptr<char> m_name;
 
+public:
   /* Interpreters are stored in a linked list, this is the next
      one...  */
-public:
   struct interp *next;
 
   /* Has the init method been run?  */
-  bool inited;
+  bool inited = false;
 };
 
 /* Look up the interpreter for NAME, creating one if none exists yet.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-22 19:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22 19:50 [binutils-gdb] Use unique_xmalloc_ptr in interp Tom Tromey

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).