[2/2] Fix resource leak found by Coverity
Commit Message
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.
---
gdb/ChangeLog | 5 +++++
gdb/interps.c | 4 +++-
gdb/interps.h | 4 +++-
3 files changed, 11 insertions(+), 2 deletions(-)
Comments
>>>>> "Gary" == Gary Benson <gbenson@redhat.com> writes:
Gary> This commit fixes a resource leak found by Coverity, where interp's
Gary> constructor allocated memory for m_name that interp's destructor did
Gary> not free.
Elsewhere Pedro asked for a different patch subject, so I think that
would apply here as well.
Gary> * interps.h (interp::m_name): Make private and mutable.
Gary> * interps.c (interp::~interp): Free m_name.
This is ok.
Tom
@@ -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. */
@@ -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? */