Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5727603ybp; Tue, 15 Oct 2019 04:15:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeasE/foQ22bthS8h4GcHzKlEm58Cm3jNPhaKcEvezFpx+3AcwotOAchgOg4cKT6AgsRec X-Received: by 2002:a05:6402:3054:: with SMTP id bu20mr31604304edb.97.1571138114331; Tue, 15 Oct 2019 04:15:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571138114; cv=none; d=google.com; s=arc-20160816; b=MgjPyHpuKIGqWuBwYr7llNaK0LuNE3K14iTdP2IAvAshtryb0hubNDShonPMGqyTVa sJE+zpoQxvAadf8mkdhait26cxATlhLtRt0t/C/eJ5OwYCerSEFddJ1mzuyLPqXDJiZB c03FwXHvAMdfx32j0TwVBmOAs4wXWuMU1cTDoLADJJTNuNoM+OcTzteRSgCmPr3Q+PSt 4Zej5dcNekC5bAI+80D6FQibb/JbAcLc/C6KIT4ghy4VaqK51k7JXXnNT55oFHY4c2qv x30zxQkAmI35UGV7qZr9wyhBZ2A4Fdm/SqUd20E+npHDEUJ8Ahyad7vWPFTq6T7T11oE paqA== 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:from:date; bh=eO67nWs35D0kcOiVhOqFVTl/HZYUI0T59gkz3R8pmjo=; b=sJvUSTEmpEAMQJgNGF1UoFXX4F5M/x5eSZoJPE3FN8wW1Vl7Smj7T/GmCCE61hN8TI eojsmLz86zl3BnNL+XwEuCfM063Dp7FPcvekqvDvabNZX1cJe9LSv0dOVH6xXdjMAF4R 85bktYo4UeGl/xQQrifGzlJg5tDGcn7GDIgjSl1AH4jrfwtRUYAs6jPaL0xkHdTUZ4b/ 9ot6iEnY0YQzWMxZdTCImwcjSkFjg6Y1F61REfz4lMxmW+6wodoiKlCvYe+Z4D5ciygC YHfkG8+y9XLGPhrG25Tj81cEfOOo7/yCV6tekTE068A7oruh6YDHNUBD5E0qsIDvmgjZ LMag== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f15si13185812edm.414.2019.10.15.04.14.50; Tue, 15 Oct 2019 04:15:14 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729349AbfJOIr4 (ORCPT + 99 others); Tue, 15 Oct 2019 04:47:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56668 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726430AbfJOIr4 (ORCPT ); Tue, 15 Oct 2019 04:47:56 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 259FB7F746; Tue, 15 Oct 2019 08:47:56 +0000 (UTC) Received: from krava (unknown [10.43.17.61]) by smtp.corp.redhat.com (Postfix) with SMTP id 3608C19C68; Tue, 15 Oct 2019 08:47:54 +0000 (UTC) Date: Tue, 15 Oct 2019 10:47:53 +0200 From: Jiri Olsa To: Yunfeng Ye Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, hushiyuan@huawei.com, linfeilong@huawei.com Subject: Re: [PATCH] perf c2c: fix memory leak in build_cl_output() Message-ID: <20191015084753.GD10951@krava> References: <4d3c0178-5482-c313-98e1-f82090d2d456@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4d3c0178-5482-c313-98e1-f82090d2d456@huawei.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Tue, 15 Oct 2019 08:47:56 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 15, 2019 at 10:54:14AM +0800, Yunfeng Ye wrote: > There is a memory leak problem in the failure paths of > build_cl_output(), so fix it. > > Signed-off-by: Yunfeng Ye Acked-by: Jiri Olsa thanks, jirka > --- > tools/perf/builtin-c2c.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c > index 3542b6a..e69f449 100644 > --- a/tools/perf/builtin-c2c.c > +++ b/tools/perf/builtin-c2c.c > @@ -2635,6 +2635,7 @@ static int build_cl_output(char *cl_sort, bool no_source) > bool add_sym = false; > bool add_dso = false; > bool add_src = false; > + int ret = 0; > > if (!buf) > return -ENOMEM; > @@ -2653,7 +2654,8 @@ static int build_cl_output(char *cl_sort, bool no_source) > add_dso = true; > } else if (strcmp(tok, "offset")) { > pr_err("unrecognized sort token: %s\n", tok); > - return -EINVAL; > + ret = -EINVAL; > + goto err; > } > } > > @@ -2676,13 +2678,15 @@ static int build_cl_output(char *cl_sort, bool no_source) > add_sym ? "symbol," : "", > add_dso ? "dso," : "", > add_src ? "cl_srcline," : "", > - "node") < 0) > - return -ENOMEM; > + "node") < 0) { > + ret = -ENOMEM; > + goto err; > + } > > c2c.show_src = add_src; > - > +err: > free(buf); > - return 0; > + return ret; > } > > static int setup_coalesce(const char *coalesce, bool no_source) > -- > 2.7.4.3 >