Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3600ybg; Fri, 25 Oct 2019 15:34:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLxlVXAORVpTQDyjbyS4A07xlp3wZu+5e2qMj5LaV7qfS9QNdBlhAzD/Et3SK9uAfqAaCk X-Received: by 2002:a50:8871:: with SMTP id c46mr6735753edc.24.1572042864938; Fri, 25 Oct 2019 15:34:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572042864; cv=none; d=google.com; s=arc-20160816; b=tqUKVhS/qD+kAtspo5PY1zNbGjAPaC87bbJA7R8iFmOfyLtMxO/w6nxIFlbAoEIVb8 8PiyO00oYYLHiH3hx8KXN0YzndQzbEOuQ6P6dC83o6JfN+ta04QvKKbrWY68pxsz/HJx dQGcxvoNm7pRXJspxCaG8YN37OfGw5cabTwrGFg34GzeT4youAHu5XmbKSa5cwW35WYO 55x/eW4+dGMhmAUIVJSbO7oNysh79hyKYulVSgoTH2ilkhSq2QH2y+JeZ93O030WYoq1 TA9npI6jqeGZ98slUYG93WxIZG5d9TOz9w+eLCWbvIU845ik4vxkmEJsOBSFsBv4c9lW Qhbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:user-agent:in-reply-to:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=IBg/RemnUO6FrGBf0EaqOcr2gXDDQq0ETHC+883fOmI=; b=yDL4MPpJ2bHvSkKYV/QUV8Vg+SHNAdG1U4N4a46lbPZJL3+MzFQVSxEoLxQ+wcW5Wx +cf+lMV+mcOyK5WLNY9x3BPNQUdV11oYG4qaarh5yjR4q3FP/9+vzPKMoTmNGUccZdGw Imxf229NSfwQVdHp3QLjTcQ6sRssiqe8BkG0RUAKAHsG/EXlgEjWmNg3uHC5/VbbEgiW HDSA/c5rBkAsG+yHeRaafLpRHkDd6kJxIvwQrC1WFwdKP4x7qxnje3dx3gbz3qaRO//g cN+I4D/JXzM0kCaP/H+XGemYxYR5rRTw8dmbPtOYU37HES44ZRaCG7+PJAqe+PooKnOX V6Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QLizEG5H; 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=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 f27si2112620ejb.310.2019.10.25.15.34.01; Fri, 25 Oct 2019 15:34:24 -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=@redhat.com header.s=mimecast20190719 header.b=QLizEG5H; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503932AbfJYMCF (ORCPT + 99 others); Fri, 25 Oct 2019 08:02:05 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:25790 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2502539AbfJYMCE (ORCPT ); Fri, 25 Oct 2019 08:02:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572004923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IBg/RemnUO6FrGBf0EaqOcr2gXDDQq0ETHC+883fOmI=; b=QLizEG5HiQ1UD/o52bIlhmIdM6K3ICA2+5sbykhC27eRB2cuFb7VLUBk5adiYaemE/fFhm 5HMJdb1+ioPyWEI8M2wpNWanNKvIpMppmS2T2jEe1ZkiICZPC8jZxJIP37yiCJE7o2ntpP mCNTIU8ANm0dl+r4LPkwDLlqUqFdZdQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-280-9JO_5gNoPreq6XvpTBvKag-1; Fri, 25 Oct 2019 08:01:59 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC4EA800D41; Fri, 25 Oct 2019 12:01:57 +0000 (UTC) Received: from krava (unknown [10.43.17.61]) by smtp.corp.redhat.com (Postfix) with SMTP id 8A7DC5D9CA; Fri, 25 Oct 2019 12:01:55 +0000 (UTC) Date: Fri, 25 Oct 2019 14:01:54 +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 c2c_he_zalloc() Message-ID: <20191025120154.GA25352@krava> References: <9d5f26f8-9429-bcb6-d491-cb789f761ea2@huawei.com> MIME-Version: 1.0 In-Reply-To: <9d5f26f8-9429-bcb6-d491-cb789f761ea2@huawei.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: 9JO_5gNoPreq6XvpTBvKag-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 25, 2019 at 05:42:47PM +0800, Yunfeng Ye wrote: > A memory leak in c2c_he_zalloc() is found by visual inspection. >=20 > Fix this by adding memory free on the error paths in c2c_he_zalloc(). >=20 > Fixes: 7f834c2e84bb ("perf c2c report: Display node for cacheline address= ") > Fixes: 1e181b92a2da ("perf c2c report: Add 'node' sort key") > Signed-off-by: Yunfeng Ye Acked-by: Jiri Olsa thanks, jirka > --- > tools/perf/builtin-c2c.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) >=20 > diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c > index e69f44941aad..ad7d38a9dcbe 100644 > --- a/tools/perf/builtin-c2c.c > +++ b/tools/perf/builtin-c2c.c > @@ -138,21 +138,29 @@ static void *c2c_he_zalloc(size_t size) >=20 > =09c2c_he->cpuset =3D bitmap_alloc(c2c.cpus_cnt); > =09if (!c2c_he->cpuset) > -=09=09return NULL; > +=09=09goto free_c2c_he; >=20 > =09c2c_he->nodeset =3D bitmap_alloc(c2c.nodes_cnt); > =09if (!c2c_he->nodeset) > -=09=09return NULL; > +=09=09goto free_cpuset; >=20 > =09c2c_he->node_stats =3D zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_st= ats)); > =09if (!c2c_he->node_stats) > -=09=09return NULL; > +=09=09goto free_nodeset; >=20 > =09init_stats(&c2c_he->cstats.lcl_hitm); > =09init_stats(&c2c_he->cstats.rmt_hitm); > =09init_stats(&c2c_he->cstats.load); >=20 > =09return &c2c_he->he; > + > +free_nodeset: > +=09free(c2c_he->nodeset); > +free_cpuset: > +=09free(c2c_he->cpuset); > +free_c2c_he: > +=09free(c2c_he); > +=09return NULL; > } >=20 > static void c2c_he_free(void *he) > --=20 > 2.7.4 >=20