[1/2] Fix resource leak found by Coverity

Message ID 1539176277-4500-2-git-send-email-gbenson@redhat.com
State New, archived
Headers

Commit Message

Gary Benson Oct. 10, 2018, 12:57 p.m. UTC
  This commit fixes a resource leak found by Coverity, where cli_interp's
constructor creates a new cli_ui_out, but there was no corresponding
destructor to free it.

gdb/ChangeLog:

	* cli/cli-interp.c (cli_interp::~cli_interp): New function.
---
 gdb/ChangeLog        | 4 ++++
 gdb/cli/cli-interp.c | 6 ++++++
 2 files changed, 10 insertions(+)
  

Comments

Tom Tromey Oct. 10, 2018, 4:02 p.m. UTC | #1
>>>>> "Gary" == Gary Benson <gbenson@redhat.com> writes:

Gary> This commit fixes a resource leak found by Coverity, where cli_interp's
Gary> constructor creates a new cli_ui_out, but there was no corresponding
Gary> destructor to free it.

Same deal with the patch title.

Gary> 	* cli/cli-interp.c (cli_interp::~cli_interp): New function.

I wonder if it's possible for the ui-out to be used after the
interpreter is destroyed.  A simple check with valgrind would show that,
I think.

This is ok if that succeeds.

Tom
  

Patch

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 2aa41d6..75d8093 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -44,6 +44,7 @@  class cli_interp final : public cli_interp_base
 {
  public:
   explicit cli_interp (const char *name);
+  ~cli_interp ();
 
   void init (bool top_level) override;
   void resume () override;
@@ -62,6 +63,11 @@  cli_interp::cli_interp (const char *name)
   this->cli_uiout = cli_out_new (gdb_stdout);
 }
 
+cli_interp::~cli_interp ()
+{
+  delete cli_uiout;
+}
+
 /* Suppress notification struct.  */
 struct cli_suppress_notification cli_suppress_notification =
   {