Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp165355ybg; Tue, 2 Jun 2020 20:05:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+rw1W33zwzse3hGswcvQG7NFIo7X4geSEw4AfzTIHOYZ0///FZo7oqHHOW1WoNc1A+KUq X-Received: by 2002:aa7:d054:: with SMTP id n20mr4452553edo.344.1591153557279; Tue, 02 Jun 2020 20:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591153557; cv=none; d=google.com; s=arc-20160816; b=AnHRVjSBw+GPHsaukPY8wM8uSmBFgiKf1uKILnbUjK3NWjP1veN8CFxaE/Ho1CuQQp hGTUxuGykErkhvk9R7wV81+irVALJnW2eS9Jq1J3Q4PWFsGQNy2hfmf3/Ztk+bqO6AqQ 6Ifw8MsIBO7K69IiXsbdecfUCuNqZ7a8SkdiPV2+VvJLuW+3OrMHGgC06iTKur0ZIpIL nkQBWGfklFG+nq+YMHEQZha+Ik/bqA+Q/Ux90JArnsLKGW0B35nf1cCRVVdm+ZDKDYK+ p311X7SIfhDOsDKfiESUAY55eP/74S6fxV/ux/AmG2hE0/wAxugUyJOjkmPh6bp6DIGA LLew== 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:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=h5+dFHvFMLiAaCHsO+4pG5C3w1p6kNupKpI1VimiaxA=; b=T+sZ6ZiOsBi4PjzsaJO05QOXI3HTC+8EYdIkaybju/OLFB6zASoKBG83DVw5jynWt3 x1e96EaNw+HKgKNIitxlxB3pSLd9D7ANif48kEfFY0m9KMH0RrT8nozLgmbfqHbOrklk anYhhQgHUb7fh4ftzL0hBPgX6f+dZISDl+0YdjJtQmFEzOdr+ovswVKP2K1Cw6mMN4kt EaoSAle1aKOM8uXgarGSXFZVMFDHQ9Gsb19Zu+Z3ORRWFGQIK0z3EVQsj7im6fPIoqLq rnYcbLR39IHKNiPQQth2shaD1jjt9/6+3k3NDS444/2ZM3QAL3O7DDnJhIg0o9b7xLBP ByNA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qu2si434853ejb.89.2020.06.02.20.05.34; Tue, 02 Jun 2020 20:05:57 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725927AbgFCDDg (ORCPT + 99 others); Tue, 2 Jun 2020 23:03:36 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:41256 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725780AbgFCDDg (ORCPT ); Tue, 2 Jun 2020 23:03:36 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id E19243405ACD07594765; Wed, 3 Jun 2020 11:03:33 +0800 (CST) Received: from [127.0.0.1] (10.166.215.91) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Wed, 3 Jun 2020 11:03:21 +0800 Subject: Re: [PATCH 2/4] perf svghelper: Fix memory leak in svg_build_topology_map To: Arnaldo Carvalho de Melo , Wei Li CC: Alexander Shishkin , Jiri Olsa , Mark Rutland , Namhyung Kim , , Xie XiuQi , Hongbo Yao References: <20200521133218.30150-1-liwei391@huawei.com> <20200521133218.30150-3-liwei391@huawei.com> <20200521141545.GC3898@kernel.org> From: "LiBin (Huawei)" Message-ID: <36b0d67c-f8a0-09b2-c2c7-964e202710d2@huawei.com> Date: Wed, 3 Jun 2020 11:03:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200521141545.GC3898@kernel.org> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.166.215.91] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2020/5/21 22:15, Arnaldo Carvalho de Melo ะด??: > Em Thu, May 21, 2020 at 09:32:16PM +0800, Wei Li escreveu: >> From: Li Bin >> >> Fix leak of memory pointed to by t.sib_thr and t.sib_core in >> svg_build_topology_map. >> >> Signed-off-by: Li Bin >> --- >> tools/perf/util/svghelper.c | 10 +++++++--- >> 1 file changed, 7 insertions(+), 3 deletions(-) >> >> diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c >> index 96f941e01681..e2b3b0e2fafe 100644 >> --- a/tools/perf/util/svghelper.c >> +++ b/tools/perf/util/svghelper.c >> @@ -754,6 +754,7 @@ int svg_build_topology_map(struct perf_env *env) >> int i, nr_cpus; >> struct topology t; >> char *sib_core, *sib_thr; >> + int ret; > Please set ret to -1 here > > int ret = -1; > > So that you don't have to add all those lines below... > >> >> nr_cpus = min(env->nr_cpus_online, MAX_NR_CPUS); >> >> @@ -767,12 +768,14 @@ int svg_build_topology_map(struct perf_env *env) >> >> if (!t.sib_core || !t.sib_thr) { >> fprintf(stderr, "topology: no memory\n"); >> + ret = -1; >> goto exit; >> } >> >> for (i = 0; i < env->nr_sibling_cores; i++) { >> if (str_to_bitmap(sib_core, &t.sib_core[i], nr_cpus)) { >> fprintf(stderr, "topology: can't parse siblings map\n"); >> + ret = -1; >> goto exit; >> } >> >> @@ -782,6 +785,7 @@ int svg_build_topology_map(struct perf_env *env) >> for (i = 0; i < env->nr_sibling_threads; i++) { >> if (str_to_bitmap(sib_thr, &t.sib_thr[i], nr_cpus)) { >> fprintf(stderr, "topology: can't parse siblings map\n"); >> + ret = -1; >> goto exit; >> } >> >> @@ -791,6 +795,7 @@ int svg_build_topology_map(struct perf_env *env) >> topology_map = malloc(sizeof(int) * nr_cpus); >> if (!topology_map) { >> fprintf(stderr, "topology: no memory\n"); >> + ret = -1; >> goto exit; >> } >> >> @@ -798,12 +803,11 @@ int svg_build_topology_map(struct perf_env *env) >> topology_map[i] = -1; >> >> scan_core_topology(topology_map, &t, nr_cpus); >> - >> - return 0; > ... as you'll set it to zero here :-) Thank you for your comments. I will fix it. Thanks, Li Bin >> + ret = 0; >> >> exit: >> zfree(&t.sib_core); >> zfree(&t.sib_thr); >> >> - return -1; >> + return ret; >> } >> -- >> 2.17.1 >>