This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix interp::m_name resource leak found by Coverity


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

commit fbe61a3661b083a666e6550b3b0c2de364e6d4a6
Author: Gary Benson <gbenson@redhat.com>
Date:   Thu Oct 11 10:19:26 2018 +0100

    Fix interp::m_name resource leak found by Coverity
    
    This commit fixes a resource leak found by Coverity, where interp's
    constructor allocated memory for m_name that interp's destructor did
    not free.
    
    gdb/ChangeLog:
    
    	* interps.h (interp::m_name): Make private and mutable.
    	* interps.c (interp::~interp): Free m_name.

Diff:
---
 gdb/ChangeLog | 5 +++++
 gdb/interps.c | 4 +++-
 gdb/interps.h | 4 +++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e28b464..b3cc646 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-10-11  Gary Benson <gbenson@redhat.com>
+
+	* interps.h (interp::m_name): Make private and mutable.
+	* interps.c (interp::~interp): Free m_name.
+
 2018-10-10  Sergio Durigan Junior  <sergiodj@redhat.com>
 	    Simon Marchi <simark@simark.ca>
 
diff --git a/gdb/interps.c b/gdb/interps.c
index 6fe4c74..883e042 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -84,7 +84,9 @@ interp::interp (const char *name)
 }
 
 interp::~interp ()
-{}
+{
+  xfree (m_name);
+}
 
 /* An interpreter factory.  Maps an interpreter name to the factory
    function that instantiates an interpreter by that name.  */
diff --git a/gdb/interps.h b/gdb/interps.h
index 74c9a80..dbf91f1 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -80,10 +80,12 @@ public:
   }
 
   /* This is the name in "-i=" and "set interpreter".  */
-  const char *m_name;
+private:
+  char *m_name;
 
   /* Interpreters are stored in a linked list, this is the next
      one...  */
+public:
   struct interp *next;
 
   /* Has the init method been run?  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]