Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7488581ybp; Wed, 16 Oct 2019 09:22:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyi0/jWBQ9d6J9AI6z1EgimWofFpbJ5yojLrzMyi43AZC4UTKziKUfe2cVTdZlx5VXku25W X-Received: by 2002:a17:906:1e07:: with SMTP id g7mr41571902ejj.256.1571242961933; Wed, 16 Oct 2019 09:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571242961; cv=none; d=google.com; s=arc-20160816; b=fUOgGZD4D1fYKf6ovOx0B5Wj5PQDA71Lih5oZbjjuouashhXf6XBQ7OtYJ7l6Jj2P5 kDGOu3LTy3jQ6brwfQdMIeYkuwSOGhexhg6JAd7KM39nGJRrYhW5Xl7XHSRhY8mDJcO4 IsNqE+CABu8HS9ANBcfd75E2+WkV6Ix7SHawZq/HrF/65XRNmjSTp/GGZIUqzQxNjdko neBFBB6PpLTLSOVpkyS3uI7HHkrqEWDtQpLsEGu/ZXYE5ZiKn3hnUTdhbKKAs9gD+ZJL 0RDdYNLkcnVV+H1IR/N7XCXUDw/HC0GY1BRfAGoBDqi6/xYIsvuRAFZb7ihxAMUBCVaG 42cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=Y4EQYL75ejH4E6buXrBDGLhTfNE3a0xcUuB5fdXMSbo=; b=1K47mOQNUh/6kaumzolWCsd6WnRc9LbOZwLseS0H587rehyef8x3LF1jOg14oHYDf8 AzXaho+DHGIab9hAqvBYsxatUE0hhDgxj+ApJPlxPRegJ9T9aigfpg51gF0Ti6coWvpe xbIIqLjy3lAUqElAqR8H+nwl2gflYKIjHed7IJ7Hpn3RGIKdJCBTCwG6mczPdKXdAhyi BnZ/VmTJcdEJqkN7ImoQfF9pFp/eAYaOew0fAWYz6VB+BwwlGbf5H5KfYf/cH2e0lOxA 5Hv+T0rcBn3Dxp64XcBhpKtrm8aITIXaGBVWdG3twpOo65LWZD0jxInkk2lwrRLwD6bj SKUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rtzSFNoF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si17928734edk.157.2019.10.16.09.22.18; Wed, 16 Oct 2019 09:22:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rtzSFNoF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393942AbfJPOZm (ORCPT + 99 others); Wed, 16 Oct 2019 10:25:42 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:34810 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726750AbfJPOZl (ORCPT ); Wed, 16 Oct 2019 10:25:41 -0400 Received: by mail-qt1-f196.google.com with SMTP id 3so36434566qta.1 for ; Wed, 16 Oct 2019 07:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Y4EQYL75ejH4E6buXrBDGLhTfNE3a0xcUuB5fdXMSbo=; b=rtzSFNoFtdbPX0n8kfiZENC2xSjazQH8VXjl9lodLsafn/bABXG9TXSs0/kdUUx49A gNRnTmxQDl5DnoqzJqNKjWxGYsTf69VTnLEEIElF0SWvSQMRXcMa2EC6AeT7iQG6hnio GYrSQXmF43e2/8JQ/5Zspa043MM34PVWSLfg2BlolIhRENpR04W2mgjKM5X3zld8l6Z9 4nLiL5fZ6CmzKmatDtB/QRcSi3HcW5owvdGVfm1uDdTz+x4S3/loVNC27Y5rTX0KMYMm mO8f2Z7Rx4xoMttbjtqI6Uk5XPLVc3IGIJTDf7IRoBc02J7/IpLRQYAwGDZOiGRW/7vP jjvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Y4EQYL75ejH4E6buXrBDGLhTfNE3a0xcUuB5fdXMSbo=; b=lR76+F5blb4eroMoFROG3aY8JTesz4jhLpKCl64JgGGUODGJK3+IfxM850lkQAXvqZ Wa5MfDjdITLy2XL2NFjPTz9+hsbLIBpJZG9eooRY3+sNmOc+2rLMn/eRSZFQmO6v48Vy U/pkzafgQQKd9NKj6G3xoPgf5Mj2VkcRcI+0br7DLdfH+7bzDcGkfXdeyR7TpbomuFjU Mku25/rOTHnW+sf0iM3AL3ZWdXHGWj2oadZHQoyLtjtrOfqnOCs24kisdRCglb46Sl5V mtwQ751E/sgpyL1AP5gZaxuH1T7Uq8c0RPBRVl06T15waHP5aExobagF/XMGC5xJKd7m TqgQ== X-Gm-Message-State: APjAAAUSKJlq+ddXvk7f7Dd96otojqeMh1e96Ewv7Y4ZrjrMi7u7L1HA AiSiKpZqeODNyoiTctdVUWE= X-Received: by 2002:a0c:bf45:: with SMTP id b5mr41462664qvj.150.1571235938895; Wed, 16 Oct 2019 07:25:38 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.35.50]) by smtp.gmail.com with ESMTPSA id r55sm13644479qtj.86.2019.10.16.07.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2019 07:25:38 -0700 (PDT) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 3C2554DD66; Wed, 16 Oct 2019 11:25:36 -0300 (-03) Date: Wed, 16 Oct 2019 11:25:36 -0300 To: Yunfeng Ye Cc: peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, john.garry@huawei.com, ak@linux.intel.com, lukemujica@google.com, kan.liang@linux.intel.com, yuzenghui@huawei.com, "linux-kernel@vger.kernel.org" , hushiyuan@huawei.com, linfeilong@huawei.com Subject: Re: [PATCH v2] perf jevents: Fix resource leak in process_mapfile() and main() Message-ID: <20191016142536.GH22835@kernel.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Oct 16, 2019 at 09:50:17PM +0800, Yunfeng Ye escreveu: > There are memory leaks and file descriptor resource leaks in > process_mapfile() and main(). > > Fix this by adding free(), fclose() and free_arch_std_events() > on the error paths. > > Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file") > Fixes: 3f056b66647b ("perf jevents: Make build fail on JSON parse error") > Fixes: e9d32c1bf0cd ("perf vendor events: Add support for arch standard events") Nice, thanks for adding the fixes line, I looked at those three patches and indeed they were leaky, thanks for the fixes, we shouldn't have those leaks even if that, for now, makes the tool to end anyway. - Arnaldo > Signed-off-by: Yunfeng Ye > --- > v1 -> v2: > - add free(eventsfp) to fix eventsfp resource leaks > - add free_arch_std_events() on the error path > > tools/perf/pmu-events/jevents.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c > index e2837260ca4d..99e3fd04a5cb 100644 > --- a/tools/perf/pmu-events/jevents.c > +++ b/tools/perf/pmu-events/jevents.c > @@ -758,6 +758,7 @@ static int process_mapfile(FILE *outfp, char *fpath) > char *line, *p; > int line_num; > char *tblname; > + int ret = 0; > > pr_info("%s: Processing mapfile %s\n", prog, fpath); > > @@ -769,6 +770,7 @@ static int process_mapfile(FILE *outfp, char *fpath) > if (!mapfp) { > pr_info("%s: Error %s opening %s\n", prog, strerror(errno), > fpath); > + free(line); > return -1; > } > > @@ -795,7 +797,8 @@ static int process_mapfile(FILE *outfp, char *fpath) > /* TODO Deal with lines longer than 16K */ > pr_info("%s: Mapfile %s: line %d too long, aborting\n", > prog, fpath, line_num); > - return -1; > + ret = -1; > + goto out; > } > line[strlen(line)-1] = '\0'; > > @@ -825,7 +828,9 @@ static int process_mapfile(FILE *outfp, char *fpath) > > out: > print_mapping_table_suffix(outfp); > - return 0; > + fclose(mapfp); > + free(line); > + return ret; > } > > /* > @@ -1122,6 +1127,7 @@ int main(int argc, char *argv[]) > goto empty_map; > } else if (rc < 0) { > /* Make build fail */ > + fclose(eventsfp); > free_arch_std_events(); > return 1; > } else if (rc) { > @@ -1134,6 +1140,7 @@ int main(int argc, char *argv[]) > goto empty_map; > } else if (rc < 0) { > /* Make build fail */ > + fclose(eventsfp); > free_arch_std_events(); > return 1; > } else if (rc) { > @@ -1151,6 +1158,8 @@ int main(int argc, char *argv[]) > if (process_mapfile(eventsfp, mapfile)) { > pr_info("%s: Error processing mapfile %s\n", prog, mapfile); > /* Make build fail */ > + fclose(eventsfp); > + free_arch_std_events(); > return 1; > } > > -- > 2.7.4.3 -- - Arnaldo