From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id C181A387086F for ; Sun, 10 May 2020 19:58:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C181A387086F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mark@klomp.org Received: from librem (deer0x15.wildebeest.org [172.31.17.151]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 89F03300B2FD; Sun, 10 May 2020 21:58:01 +0200 (CEST) Received: by librem (Postfix, from userid 1000) id 630C8C031D; Sun, 10 May 2020 21:57:36 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: David Malcolm , Mark Wielaard Subject: [PATCH 1/7] libdwfl: Cleanup user_core resources on failure in dwfl_core_file_report. Date: Sun, 10 May 2020 21:53:34 +0200 Message-Id: <20200510195339.37191-2-mark@klomp.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200510195339.37191-1-mark@klomp.org> References: <20200510195339.37191-1-mark@klomp.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 May 2020 19:58:03 -0000 GCC10 -fanalyzer noticed that we allocate, but don't always cleanup the dwfl->user_core if it wasn't set yet on error. In theory dwfl_module_end should take care of it, but it is cleaner and less confusing to just do it here. Signed-off-by: Mark Wielaard --- libdwfl/ChangeLog | 6 ++++++ libdwfl/core-file.c | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 3f9cd665..05d5bd4a 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,9 @@ +2020-05-08 Mark Wielaard + + * libdwfl/core-file.c (dwfl_core_file_report): Keep track of + new bool cleanup_user_core and cleanup dwfl->user_core in error + case. + 2020-04-30 Mark Wielaard * find-debuginfo.c (dwfl_standard_find_debuginfo): When mod->dw diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c index 01109f4b..a0ccc9b3 100644 --- a/libdwfl/core-file.c +++ b/libdwfl/core-file.c @@ -450,6 +450,7 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const char *executable) return -1; } + bool cleanup_user_core = false; if (dwfl->user_core != NULL) free (dwfl->user_core->executable_for_core); if (executable == NULL) @@ -461,6 +462,7 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const char *executable) { if (dwfl->user_core == NULL) { + cleanup_user_core = true; dwfl->user_core = calloc (1, sizeof (struct Dwfl_User_Core)); if (dwfl->user_core == NULL) { @@ -472,6 +474,11 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const char *executable) dwfl->user_core->executable_for_core = strdup (executable); if (dwfl->user_core->executable_for_core == NULL) { + if (cleanup_user_core) + { + free (dwfl->user_core); + dwfl->user_core = NULL; + } __libdwfl_seterrno (DWFL_E_NOMEM); return -1; } @@ -481,7 +488,15 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const char *executable) GElf_Phdr notes_phdr; int ndx = dwfl_report_core_segments (dwfl, elf, phnum, ¬es_phdr); if (unlikely (ndx <= 0)) - return ndx; + { + if (cleanup_user_core) + { + free (dwfl->user_core->executable_for_core); + free (dwfl->user_core); + dwfl->user_core = NULL; + } + return ndx; + } /* Next, we should follow the chain from DT_DEBUG. */ -- 2.20.1