public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Fix resource leak found by Coverity
  2018-10-10 12:58 [PATCH 0/2] Fix resource leaks found by Coverity Gary Benson
  2018-10-10 12:58 ` [PATCH 2/2] Fix resource leak " Gary Benson
@ 2018-10-10 12:58 ` Gary Benson
  2018-10-10 16:02   ` Tom Tromey
  1 sibling, 1 reply; 5+ messages in thread
From: Gary Benson @ 2018-10-10 12:58 UTC (permalink / raw)
  To: gdb-patches

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(+)

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 =
   {
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 0/2] Fix resource leaks found by Coverity
@ 2018-10-10 12:58 Gary Benson
  2018-10-10 12:58 ` [PATCH 2/2] Fix resource leak " Gary Benson
  2018-10-10 12:58 ` [PATCH 1/2] " Gary Benson
  0 siblings, 2 replies; 5+ messages in thread
From: Gary Benson @ 2018-10-10 12:58 UTC (permalink / raw)
  To: gdb-patches

Hi all,

These two patches fix resource leaks found by Coverity,
where resources allocated by constructors were not freed
by the relevant destructors.

Built and regtested on RHEL 7.5 x86_64.

Ok to commit?

Thanks,
Gary

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] Fix resource leak found by Coverity
  2018-10-10 12:58 [PATCH 0/2] Fix resource leaks found by Coverity Gary Benson
@ 2018-10-10 12:58 ` Gary Benson
  2018-10-10 16:01   ` Tom Tromey
  2018-10-10 12:58 ` [PATCH 1/2] " Gary Benson
  1 sibling, 1 reply; 5+ messages in thread
From: Gary Benson @ 2018-10-10 12:58 UTC (permalink / raw)
  To: gdb-patches

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

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?  */
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] Fix resource leak found by Coverity
  2018-10-10 12:58 ` [PATCH 2/2] Fix resource leak " Gary Benson
@ 2018-10-10 16:01   ` Tom Tromey
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2018-10-10 16:01 UTC (permalink / raw)
  To: Gary Benson; +Cc: gdb-patches

>>>>> "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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] Fix resource leak found by Coverity
  2018-10-10 12:58 ` [PATCH 1/2] " Gary Benson
@ 2018-10-10 16:02   ` Tom Tromey
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2018-10-10 16:02 UTC (permalink / raw)
  To: Gary Benson; +Cc: gdb-patches

>>>>> "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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-10-10 16:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-10 12:58 [PATCH 0/2] Fix resource leaks found by Coverity Gary Benson
2018-10-10 12:58 ` [PATCH 2/2] Fix resource leak " Gary Benson
2018-10-10 16:01   ` Tom Tromey
2018-10-10 12:58 ` [PATCH 1/2] " Gary Benson
2018-10-10 16:02   ` 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).