From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71783 invoked by alias); 5 Jun 2018 20:44:34 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 70738 invoked by uid 89); 5 Jun 2018 20:44:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.4 on sourceware.org X-Virus-Found: No 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,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=belongs X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Jun 2018 20:44:31 +0000 Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 39C0D3000913; Tue, 5 Jun 2018 22:44:29 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 2C783418ABCC; Tue, 5 Jun 2018 22:44:29 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] libdw: Don't leak arange if we cannot figure out which CU it belongs to. Date: Tue, 05 Jun 2018 20:44:00 -0000 Message-Id: <1528231467-2742-1-git-send-email-mark@klomp.org> X-Mailer: git-send-email 1.8.3.1 X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2018-q2/txt/msg00154.txt.bz2 In the unlikely case that __libdw_findcu fails to find the associated CU we would leak one arange because it wasn't linked into the arangelist list yet. Make sure to free it immediately. Signed-off-by: Mark Wielaard --- libdw/ChangeLog | 5 +++++ libdw/dwarf_getaranges.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index f0ce901..661fa9d 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,5 +1,10 @@ 2018-06-05 Mark Wielaard + * dwarf_getaranges (dwarf_getaranges): Free new_arange if + __libdw_findcu fails. + +2018-06-05 Mark Wielaard + * dwarf_getsrclines.c (read_srclines): Define dirarray early and check whether or not it is equal to dirstack on exit/out before cleanup. diff --git a/libdw/dwarf_getaranges.c b/libdw/dwarf_getaranges.c index 50a98cf..bff9c86 100644 --- a/libdw/dwarf_getaranges.c +++ b/libdw/dwarf_getaranges.c @@ -197,7 +197,12 @@ dwarf_getaranges (Dwarf *dbg, Dwarf_Aranges **aranges, size_t *naranges) /* We store the actual CU DIE offset, not the CU header offset. */ Dwarf_CU *cu = __libdw_findcu (dbg, offset, false); if (unlikely (cu == NULL)) - goto fail; + { + /* We haven't gotten a chance to link in the new_arange + into the arangelist, don't leak it. */ + free (new_arange); + goto fail; + } new_arange->arange.offset = __libdw_first_die_off_from_cu (cu); new_arange->next = arangelist; -- 1.8.3.1