From patchwork Wed Oct 10 13:52:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 29696 Received: (qmail 54362 invoked by alias); 10 Oct 2018 13:53:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 54339 invoked by uid 89); 10 Oct 2018 13:53:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=valopsc, UD:valops.c, valops.c, champion X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 10 Oct 2018 13:53:03 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9006D80467 for ; Wed, 10 Oct 2018 13:53:02 +0000 (UTC) Received: from blade.nx (ovpn-117-250.ams2.redhat.com [10.36.117.250]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B16283EBD for ; Wed, 10 Oct 2018 13:53:02 +0000 (UTC) Received: from blade.com (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 53CC880B0905 for ; Wed, 10 Oct 2018 14:53:01 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH] Fix resource leak found by Coverity Date: Wed, 10 Oct 2018 14:52:58 +0100 Message-Id: <1539179578-32250-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes 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) {