Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2943059rwb; Mon, 5 Sep 2022 04:11:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR7mA/JsUEgQRq/9bcX5gEn7g62jn3Vt8pKmuAVaKvXjIQSpb9VPmIoMsF2Y0N76IaK38DFX X-Received: by 2002:a63:6b02:0:b0:422:7cf8:4bf with SMTP id g2-20020a636b02000000b004227cf804bfmr42487827pgc.92.1662376272425; Mon, 05 Sep 2022 04:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662376272; cv=none; d=google.com; s=arc-20160816; b=HqxB9fOGGiCmXAUT6WK3VZ7c3g4sWh1ssM8dpLp/eOKClTLMvP1ige1zbYfbvwqXgw 3BZ4LtvPndANjDRE2nXakl/0JNj7Ydv3AxJ7YPVcYrV70j+a1ImVzOYRxlsfcRuzIo18 ldJX9WWQPUfb86Z1J/q5PwPObXQw/k6CMpQ6zGALbQDsA6qirRbw8kG51uoakZG7Z1A3 89JGshSqzhqEzaktvK6OCQT5ZHdtBRA2BqTSu/UP3cWDczjEJNa8As2ZgyCV38h4QoK+ KWh3FN2e1LGaIJPGbkJIomzUDWcZXkMNmPOfT8IJqyhKmtWNjYt9qy9ZEzADnLll85cl rBYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=hq9S7cyR2dxsLgQQf9Da5fdBhaAZlofiS7OnzuWQkA4=; b=E6QcfcM//g6TRjhRbqAGvLI8Dqs/TXv7Hu4/GCVYtWIDarZj72e4P+p4oqPUlvG+6r 4c89deBNXyqJn44uEBlRGInpQqj/kRv8CDdnafFcVxtCvDMKgCRLB9SGup3RxIdu1oUE qTTCjzTQiqzc842hV/reOFi4uLD7POgxBnKmP45NMYVW/IzjGMeLi4P6V4xFLKemNFcC shAJWfCRwSm/r2b00rzw5mBLrNhB+wtMg9ZXNMrmXL8/6JUzoop3GSI7SjSxrZMCYgBC lQv521mLsLvwexT+Sjm10OIcdqLr5jQuvJBXoMT7dKbgKgaoD2HCq02P6r5iz7gMVLLL mNjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="enS/dVRc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dw7-20020a17090b094700b002005a1527f5si3330218pjb.29.2022.09.05.04.10.58; Mon, 05 Sep 2022 04:11:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="enS/dVRc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236954AbiIEKU3 (ORCPT + 99 others); Mon, 5 Sep 2022 06:20:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237307AbiIEKTp (ORCPT ); Mon, 5 Sep 2022 06:19:45 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C9AF578AF; Mon, 5 Sep 2022 03:19:14 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id nc14so16097972ejc.4; Mon, 05 Sep 2022 03:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date; bh=hq9S7cyR2dxsLgQQf9Da5fdBhaAZlofiS7OnzuWQkA4=; b=enS/dVRccNUcTzSwDmjPE7Y8IWNF/bSR24RCFsTnoWcb1emBYDfls+IxZ5lxOlNEzv GKnLEl1YGiNDbSDzm87okIIouF/6jLm7hcKKQ1MdNmIRlZiltTMFmFmC7xPu11KXu7zV pXDDKUmp4Y7Ed5bq2NZjzNZnfiTWfj2wWFhpIIXY6XXHY779JXOrfFJ0Z9KdfsWLsxev V2U0rV24RMe9rhDcAIIZYGcznHujk+6aurfDuKxetkzas+1hddLLP3umznG/lZ5ZY4So cCauNtHa9Fx0TvuCjwevyRyF0OQ4BMvVZCjDkYFZwLuHCSP1zBZBNIOu8QeBf3PGvDIG 1YDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date; bh=hq9S7cyR2dxsLgQQf9Da5fdBhaAZlofiS7OnzuWQkA4=; b=aCy+HHecJxhp386qcow9kNt4kSfrnilvSSglcIA9lqXfoxhySki17vujSgDT//5vtV L0TGoU7+x6lRqFJh8c7bKo5FjiHBH5HEDwVQn3EbyFQqcKxH8OBKuvOD5rFoXT7JZz85 fMaJLwkImwyKIuISqjziGpNG2oYNWTjndxTb+00Rg0maEQZH8FZhOgRhi5W7NZaRCy8/ bWxzHypN6wjOl4NB7XZKj4JhmsZFvO4G47mjp877MwsynDD84ZRj5zO4lWVMfbAy3Q75 YgUqVGsqcpAbOY5uiqH+PEmcJOT0mXRPONd00UBLUPUOpiK61irMc5XYKBKiWoaBwuU5 r27Q== X-Gm-Message-State: ACgBeo0lxiZ6QNk+lNFlxUTpffR/wFN4rP+aENwfHhHikpWh4CjafYYw lGj+02raZh1ozEFOuFFWf9o= X-Received: by 2002:a17:906:6a0a:b0:741:55b6:83ef with SMTP id qw10-20020a1709066a0a00b0074155b683efmr28072869ejc.210.1662373152226; Mon, 05 Sep 2022 03:19:12 -0700 (PDT) Received: from krava ([193.85.244.190]) by smtp.gmail.com with ESMTPSA id e12-20020a170906314c00b00764a76d5888sm2364475eje.27.2022.09.05.03.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 03:19:11 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Mon, 5 Sep 2022 12:19:10 +0200 To: Shang XiaoJing Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] perf c2c: Prevent potential memory leak in c2c_he_zalloc Message-ID: References: <20220903072542.27678-1-shangxiaojing@huawei.com> <20220903072542.27678-4-shangxiaojing@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220903072542.27678-4-shangxiaojing@huawei.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 03, 2022 at 03:25:42PM +0800, Shang XiaoJing wrote: > Free allocated resources when zalloc is failed for members in c2c_he, to > prevent potential memory leak in c2c_he_zalloc. > > Signed-off-by: Shang XiaoJing > --- > tools/perf/builtin-c2c.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c > index 12f272811487..5530433eda80 100644 > --- a/tools/perf/builtin-c2c.c > +++ b/tools/perf/builtin-c2c.c > @@ -146,15 +146,15 @@ static void *c2c_he_zalloc(size_t size) > > c2c_he->cpuset = bitmap_zalloc(c2c.cpus_cnt); > if (!c2c_he->cpuset) > - return NULL; > + goto out_free_he; > > c2c_he->nodeset = bitmap_zalloc(c2c.nodes_cnt); > if (!c2c_he->nodeset) > - return NULL; > + goto out_free_cpuset; > > c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats)); > if (!c2c_he->node_stats) > - return NULL; > + goto out_free_nodeset; > > init_stats(&c2c_he->cstats.lcl_hitm); > init_stats(&c2c_he->cstats.rmt_hitm); > @@ -163,6 +163,14 @@ static void *c2c_he_zalloc(size_t size) > init_stats(&c2c_he->cstats.load); > > return &c2c_he->he; nit, given that c2c_he is zero allocated we could just have single error label that would free everything for the patchset: Acked-by: Jiri Olsa thanks, jirka > + > +out_free_nodeset: > + free(c2c_he->nodeset); > +out_free_cpuset: > + free(c2c_he->cpuset); > +out_free_he: > + free(c2c_he); > + return NULL; > } > > static void c2c_he_free(void *he) > -- > 2.17.1 >