From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/2] Fix resource leak found by Coverity
Date: Wed, 10 Oct 2018 12:58:00 -0000 [thread overview]
Message-ID: <1539176277-4500-3-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1539176277-4500-1-git-send-email-gbenson@redhat.com>
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
next prev parent reply other threads:[~2018-10-10 12:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-10 12:58 [PATCH 0/2] Fix resource leaks " Gary Benson
2018-10-10 12:58 ` Gary Benson [this message]
2018-10-10 16:01 ` [PATCH 2/2] Fix resource leak " Tom Tromey
2018-10-10 12:58 ` [PATCH 1/2] " Gary Benson
2018-10-10 16:02 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1539176277-4500-3-git-send-email-gbenson@redhat.com \
--to=gbenson@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).