Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5430069ybp; Mon, 14 Oct 2019 22:36:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxyDabOOi2Hcewk1jrJQa+coJJo5rWgbJ6UdkHZ7NIAs/GBtGaeQqNKiR9S5hGed4G2AOmh X-Received: by 2002:a17:907:366:: with SMTP id rs6mr32317016ejb.232.1571117764548; Mon, 14 Oct 2019 22:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571117764; cv=none; d=google.com; s=arc-20160816; b=I1U9kQRSRC1YlzR/JePLGlZGmOSd3RzVKK0yg3ntuJ8CP3sKNRthTI3rH/2GMsqS1t l3hpFA9AhSxfmND9gYlsQYxq6+DypO9bRVZ8GIqXG7npsJH8NjqNE22geIT1dec3vZY+ 6+muQljhiQobydxL7SpbX/khTfirY5UTQfSyLFYovc7Uz8gsgz6fUPc4W8950QdWzhbq qWWRxAxRz35z1Ft/n7HlAe/NRtH9cgL+Y1Y9mGvzCOmk+y/q6xFTsf2xuYU8ZbF0UWL8 TV3CcLJJWTSKkqpENRu9yfLui+PTrr8wy+uxpqeIehbl3hZaDI95Vy8FOHNBWTDywQa3 cUdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:cc:subject :from:to; bh=oWwlPfE5dEyLYL1xNHG87he6I/Sdx4bU8f5lrsJZG2Q=; b=s/iQpnlDQNTu7/XZJm8ZQjzAlsE047x4InRZmcDuk60ddipSPgnWWHrG6BOrqLzkgH 8IWgx2p32fV6rZKXZCBS8RuAzLGthFKrZtH9eg3dKEAyURxHqKq+awk3hzFT1VLDhs7C uQWWOuRk6XXSF/SVjcAjP2pp+bDU3we0a4uAYTtZ5CCqhL4Suq73alIekxCHOY4Mu4f5 QcoiawWROr+3yG7L6KB682hzTfKHnZbTvu0NPMNLTB/C+AYGnOi26D39tfOrQ31lVS0J 9IIyOFIQARa63OZtUtkUq4gFCx4VLyU0PWQEiFO8TTIVi3J5965AzYy55RtmKBy/db+J 6WAA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r16si12266966edo.307.2019.10.14.22.35.41; Mon, 14 Oct 2019 22:36:04 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727441AbfJODLi (ORCPT + 99 others); Mon, 14 Oct 2019 23:11:38 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:3713 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726946AbfJODLi (ORCPT ); Mon, 14 Oct 2019 23:11:38 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 1172FD442D4F658B0507; Tue, 15 Oct 2019 10:54:44 +0800 (CST) Received: from [127.0.0.1] (10.177.251.225) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.439.0; Tue, 15 Oct 2019 10:54:37 +0800 To: , , , , , , From: Yunfeng Ye Subject: [PATCH] perf c2c: fix memory leak in build_cl_output() CC: , , Message-ID: <4d3c0178-5482-c313-98e1-f82090d2d456@huawei.com> Date: Tue, 15 Oct 2019 10:54:14 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.251.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a memory leak problem in the failure paths of build_cl_output(), so fix it. Signed-off-by: Yunfeng Ye --- 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