Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] Fix resource leak found by Coverity
Date: Wed, 10 Oct 2018 13:53:00 -0000	[thread overview]
Message-ID: <1539179578-32250-1-git-send-email-gbenson@redhat.com> (raw)

Hi all,

This commit fixes a resource leak found by Coverity where
find_oload_champ leaked every badness vector it calculated
bar the one it returned.

Built and regtested on RHEL 7.5 x86_64.

Ok to commit?

Thanks,
Gary

--
gdb/ChangeLog:

	* valops.c (find_oload_champ): Fix resource leak found by
	Coverity.
---
 gdb/ChangeLog | 5 +++++
 gdb/valops.c  | 9 ++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/gdb/valops.c b/gdb/valops.c
index c45caef..db2d3ed 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3024,8 +3024,6 @@ find_oload_champ (struct value **args, int nargs,
 		  struct badness_vector **oload_champ_bv)
 {
   int ix;
-  /* A measure of how good an overloaded instance is.  */
-  struct badness_vector *bv;
   /* Index of best overloaded function.  */
   int oload_champ = -1;
   /* Current ambiguity state for overload resolution.  */
@@ -3075,13 +3073,15 @@ find_oload_champ (struct value **args, int nargs,
 
       /* Compare parameter types to supplied argument types.  Skip
          THIS for static methods.  */
-      bv = rank_function (parm_types, nparms, 
+      struct badness_vector *bv
+	= rank_function (parm_types, nparms,
 			  args + static_offset,
 			  nargs - static_offset);
 
       if (!*oload_champ_bv)
 	{
 	  *oload_champ_bv = bv;
+	  bv = NULL;
 	  oload_champ = 0;
 	}
       else /* See whether current candidate is better or worse than
@@ -3095,7 +3095,9 @@ find_oload_champ (struct value **args, int nargs,
 	    oload_ambiguous = 2;
 	    break;
 	  case 2:		/* New champion, record details.  */
+	    xfree (*oload_champ_bv);
 	    *oload_champ_bv = bv;
+	    bv = NULL;
 	    oload_ambiguous = 0;
 	    oload_champ = ix;
 	    break;
@@ -3103,6 +3105,7 @@ find_oload_champ (struct value **args, int nargs,
 	  default:
 	    break;
 	  }
+      xfree (bv);
       xfree (parm_types);
       if (overload_debug)
 	{
-- 
1.8.3.1


             reply	other threads:[~2018-10-10 13:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10 13:53 Gary Benson [this message]
2018-10-10 14:11 ` Pedro Alves
2018-10-10 14:20   ` [PATCH] Fix badness vector resource leaks " Gary Benson

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=1539179578-32250-1-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