Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp879668pxk; Thu, 17 Sep 2020 20:09:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSjMORDrvRddJAnYYRA7Grm1aLXztGAy5N7auV67OHTcJlkSrZmVJKU6wNMYvOK16z5CEK X-Received: by 2002:a05:6402:6c1:: with SMTP id n1mr37193093edy.215.1600398598924; Thu, 17 Sep 2020 20:09:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398598; cv=none; d=google.com; s=arc-20160816; b=F301k63khipGoXYbhL6Pyl9/nemFuQ7YZ3/Yp6zAblZ//BuWjzlwZdPVylA0W/fxDl Gf7GOc4+ZiIj+0kSFmoxO8wT25hotCIfqXBN9ORN7X+oUH8d32tEL+36vUwFdh7sbdoK zDcWTgJpUg5DUvOWVzTKqUDcR+AkM26dLOBvMUbzkiSnDQTGHhAnHZhxNCxZQV3qrNos w06YIl5AfnJcLDcLXv6SWAtJ+sp0Rhz9/E3Uc+Ew4yLgsRTyNQdxYkWmSaLU2vkOY+3t jfK7XVJoAPX8V+0TbO3VrKXYT7yF1Wql7tJTDTxAV/GdlwiInqex5lFcncqCVPcMcMF0 zbdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m6OLFQJ4OsmJ398ZFeTPFflM3ccDgFFCBYpEKwXm+w4=; b=HsB3o1dPVRLTFwP7ox7cVMhBM39Goos5RAu5rBcvL3FZLZyEhMgsjHfUPXVwvmYsys 7/G1VC1uR3PL3vXqbmB1A9zMc2/v0XeZhjyh//5y6+pF2JGtZQbCC2rif6uXuWeZ1gSO IGi9V2yRTAcI9yuylLNOXiUPT000YCHc+I4HUuoZ9D7h2XSNkiTkY+gU/oWUuBCsEaqD fhOk1WLVmxa5Tqf5x0b3iYWFQUl6ucpoynl7kQ+//0uML8uiMjIY9fUxG446liOENIZK oKWWVRaKdANwc5cXLImjtuqNkFakDzffvcuCK1ujAs81diiTavf20yfXdi8RlGr2Boh2 CAgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Q6p3bz5G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si1157500edt.247.2020.09.17.20.09.35; Thu, 17 Sep 2020 20:09:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Q6p3bz5G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727988AbgIRDFc (ORCPT + 99 others); Thu, 17 Sep 2020 23:05:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:51638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726485AbgIRCEV (ORCPT ); Thu, 17 Sep 2020 22:04:21 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 054652311D; Fri, 18 Sep 2020 02:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394661; bh=0bEKGFe7oIvtAHae9iu607OloDUiTjaguDn3Gph6ZMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q6p3bz5GdPrM7QcqIxPNRqkRNX5D45FjJ7E35ZCD1ZDsqCr1Gqos/ijs89ZLiYLok fep7T+AdP7gb/jnr8CgHPaF2v92b7XkcGtpEaRCBWclZbtTZ6vQEuEfRQFcF1dP0Ki FrZwsFPYkGhQFv0sACvnsAgeKo2eT0CFP51mTkuU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: John Garry , Jiri Olsa , Alexander Shishkin , Andi Kleen , James Clark , Joakim Zhang , Mark Rutland , Namhyung Kim , Peter Zijlstra , Will Deacon , linuxarm@huawei.com, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 5.4 156/330] perf jevents: Fix leak of mapfile memory Date: Thu, 17 Sep 2020 21:58:16 -0400 Message-Id: <20200918020110.2063155-156-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry [ Upstream commit 3f5777fbaf04c58d940526a22a2e0c813c837936 ] The memory for global pointer is never freed during normal program execution, so let's do that in the main function exit as a good programming practice. A stray blank line is also removed. Reported-by: Jiri Olsa Signed-off-by: John Garry Cc: Alexander Shishkin Cc: Andi Kleen Cc: James Clark Cc: Joakim Zhang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Will Deacon Cc: linuxarm@huawei.com Link: http://lore.kernel.org/lkml/1583406486-154841-2-git-send-email-john.garry@huawei.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/pmu-events/jevents.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c index d36ae65ae3330..f4a0d72246cb7 100644 --- a/tools/perf/pmu-events/jevents.c +++ b/tools/perf/pmu-events/jevents.c @@ -1068,10 +1068,9 @@ static int process_one_file(const char *fpath, const struct stat *sb, */ int main(int argc, char *argv[]) { - int rc; + int rc, ret = 0; int maxfds; char ldirname[PATH_MAX]; - const char *arch; const char *output_file; const char *start_dirname; @@ -1142,7 +1141,8 @@ int main(int argc, char *argv[]) /* Make build fail */ fclose(eventsfp); free_arch_std_events(); - return 1; + ret = 1; + goto out_free_mapfile; } else if (rc) { goto empty_map; } @@ -1160,14 +1160,17 @@ int main(int argc, char *argv[]) /* Make build fail */ fclose(eventsfp); free_arch_std_events(); - return 1; + ret = 1; } - return 0; + + goto out_free_mapfile; empty_map: fclose(eventsfp); create_empty_mapping(output_file); free_arch_std_events(); - return 0; +out_free_mapfile: + free(mapfile); + return ret; } -- 2.25.1