From patchwork Wed Oct 10 12:57:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 29695 Received: (qmail 118437 invoked by alias); 10 Oct 2018 12:58: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 118403 invoked by uid 89); 10 Oct 2018 12:58:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=xfree 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 12:58:03 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 16F37308624F for ; Wed, 10 Oct 2018 12:58: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 D0BC36AD41 for ; Wed, 10 Oct 2018 12:58:01 +0000 (UTC) Received: from blade.com (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id F00B580B090B for ; Wed, 10 Oct 2018 13:58:00 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 2/2] Fix resource leak found by Coverity Date: Wed, 10 Oct 2018 13:57:57 +0100 Message-Id: <1539176277-4500-3-git-send-email-gbenson@redhat.com> In-Reply-To: <1539176277-4500-1-git-send-email-gbenson@redhat.com> References: <1539176277-4500-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes 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? */