From patchwork Mon Dec 28 12:48:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 353490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96144C43381 for ; Mon, 28 Dec 2020 14:49:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 636AF20867 for ; Mon, 28 Dec 2020 14:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438090AbgL1OV7 (ORCPT ); Mon, 28 Dec 2020 09:21:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:56246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2441252AbgL1OV6 (ORCPT ); Mon, 28 Dec 2020 09:21:58 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3EB4920731; Mon, 28 Dec 2020 14:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165302; bh=BZUg49SXJ9bvdj7cXdmmm46G9A4x6QGtph8VF/n4wwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vwI8ZTFFYmTj2P/Opqf2TxysuAqMU8oERZePrc9pYC9f4oRDXIFwPn8CnhCMj5ohS TshD34FEi8/iQgbZgOCKO3Yec+xrnH4ZrljcvIo+1RjrpGJcBNO7IjqqH3x0YmUt2W ZC4wAR+G6ijpT24aF3aImRiBIo7yj0ZcXWyt1h3k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheng Zengkai , Jiri Olsa , Alexander Shishkin , Li Bin , Mark Rutland , Namhyung Kim , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.10 485/717] =?utf-8?q?perf_record=3A_Fix_memory_leak_whe?= =?utf-8?q?n_using_--user-regs=3D=3F_to_list_registers?= Date: Mon, 28 Dec 2020 13:48:03 +0100 Message-Id: <20201228125044.198705734@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Zheng Zengkai [ Upstream commit 2eb5dd418034ecea2f7031e3d33f2991a878b148 ] When using 'perf record's option '-I' or '--user-regs=' along with argument '?' to list available register names, memory of variable 'os' allocated by strdup() needs to be released before __parse_regs() returns, otherwise memory leak will occur. Fixes: bcc84ec65ad1 ("perf record: Add ability to name registers to record") Signed-off-by: Zheng Zengkai Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Li Bin Cc: Mark Rutland Cc: Namhyung Kim Link: https://lore.kernel.org/r/20200703093344.189450-1-zhengzengkai@huawei.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/parse-regs-options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c index e687497b3aac0..a4a100425b3a2 100644 --- a/tools/perf/util/parse-regs-options.c +++ b/tools/perf/util/parse-regs-options.c @@ -54,7 +54,7 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr) #endif fputc('\n', stderr); /* just printing available regs */ - return -1; + goto error; } #ifdef HAVE_PERF_REGS_SUPPORT for (r = sample_reg_masks; r->name; r++) {