Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2593508rdb; Mon, 5 Feb 2024 11:10:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFy0WsACGneWIbML9mv+rrKa+aZh8nhAM0jF2tOEF1xpT3MmvnzFW6b20xBlMDDYkG9/Esl X-Received: by 2002:a05:6358:d04c:b0:178:f482:6e56 with SMTP id jb12-20020a056358d04c00b00178f4826e56mr1089358rwb.12.1707160242785; Mon, 05 Feb 2024 11:10:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707160242; cv=pass; d=google.com; s=arc-20160816; b=O/iH7ZydThnoVrtGn4WpOSfQfDosZUdZtT9s57wvlL6nIJ/XAjW083uf+7sJbkO38m vZ7HInlWw1B3yPXvs52eUriufeQYondcxuqoctdh6Q9qakUAOd6nH+NjV5DFdOg1Dnv0 rYQa+A4ysg2DzZX3HcF8tI/sAaHmS3FEfQ2OAIZznVUu9ft5NtBd+QDSInuDNkq8RASq 6D32ANW4Ol4/At2UA2y1yC++nBSoaXla6PK3iwz2YI31yXLyQitEVAnWOAikgjhDRCNc jvbDdzmVO4yINDO2IMmJQS4mWZ6pct2+FXUOHMAmVRkNlmhsHVRYz+vu4h+yQ60D6U6S x6dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Y/9SWYE+hPGXYTUpoESdnvjkYRJ4VdJeZBWZUX5/jXo=; fh=T8YQVl/Zm2+WjxB0q/i8IFWogRhRK/e0OUxd++lZoUQ=; b=xOowJv9yAfGVhXkGUu0KMUa3VFZuZMuX9Yua4W7pIolMTXU/eDNkI7dTTCVS2y2GXA R8x8/VHuCN5gI4em43IMclTd6yqTnQI5syfnz3gr7P/TB1p1MVpNHDH9uyQN1zvVLihb pjRTlVju8kkDfLNbU9gnqUFaUbb7jg+4fL5T/fRXUiXuhJiEvH9wt8HCRgg3jEaADsYA JcF1yUdEqGgWO93vOAQfS6gTOQTPty5Rhna2eXwChe+4YvixUvYqVJIzSgT9qrH7BxPL 5VBXTUf5VrD51x9bgziOAB+FayC8dUScrVXSzFhxvU3vHF29E7P1jbeegezdSy1lRZGV J2AQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FiL6U2P8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-53264-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53264-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXuCK+NxFf/gJ+lf3V3xM6/LYmK5LpXSLn5u7++8ntUdW+QWYInh14NthSqaICPWr/e6i5cncrOJa4lyJFwr+SmzCF+8TqHvsY5oS4/Mw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k13-20020a635a4d000000b005d77ddddadfsi305607pgm.567.2024.02.05.11.10.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 11:10:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53264-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FiL6U2P8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-53264-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53264-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B74D628AB7F for ; Mon, 5 Feb 2024 18:58:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2DC78482DF; Mon, 5 Feb 2024 18:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FiL6U2P8" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42DDC482C7; Mon, 5 Feb 2024 18:58:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159529; cv=none; b=quZOKBDo7pro3QK5jU5aR6Qssp2uQBh4IHFup5H/dSlMHCkfWH37O5URmO17hi19JSFH3eI7DMc1u08NYoIZy2N2A90kq47wi8jHVLvZl7Z47/y2qrbLGmXDAThqqxhEE89gZEeTTIyJ6JLPIPGoQT+3dG5twCFXmNKFgQ277so= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159529; c=relaxed/simple; bh=WfCVbiVD64UcCoqFBq0h3S0MaSSkABL+RCJVRJ0X68Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Y5avwIJ/3n7oOwmQazrTVfBVZbxyPnvdXdxUmTb50TRT7BsxCiMH23qB3GzXPRKfTB4255XecJtGd5CfFd80t/2bIG35/ehwd0ldFuNaF5Pn6xV3qWSgtQHi+vvbHiAqn7+Q4qquwDzPdk01uWddeJzUKq/Tl5r0Ayq+sk7fpyo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FiL6U2P8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB597C433C7; Mon, 5 Feb 2024 18:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707159528; bh=WfCVbiVD64UcCoqFBq0h3S0MaSSkABL+RCJVRJ0X68Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FiL6U2P8U2aB1r0t4SsxEk993K9gMguLFZrxzuLYwVy3zBOF5s0gwV6kcIt/pR+FG NSv51Yvf8K7xJgmxUj7qCn13dWnhfdlJY7IhLQkow1dj2800jWJfFmykmIsoit+Spm 3p65YKE1Y0e/PP/Pcc41/kDtqWFmz7t3zWPn3pfDdbRwP8Eef2P/GhMdLlPtc2yv3a LgugLEbI+jSrphpHSFW59U/YpPxB7kHZwFwEyKu9dS7M5G+kgRNzjW+RhFdjd2M1ss bf8BPMgtUjZW+W5AOMF+rhRvCzOkGCfLvOKnNd3jqx+HcPEgbwjLkyuM5nvm558u4t L8Ou+VqOxJoYA== Date: Mon, 5 Feb 2024 15:58:44 -0300 From: Arnaldo Carvalho de Melo To: Yang Jihong Cc: peterz@infradead.org, mingo@redhat.com, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/5] perf sched: Fix memory leak in perf_sched__map() Message-ID: References: <20240205104616.132417-1-yangjihong1@huawei.com> <20240205104616.132417-3-yangjihong1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240205104616.132417-3-yangjihong1@huawei.com> On Mon, Feb 05, 2024 at 10:46:13AM +0000, Yang Jihong wrote: > +++ b/tools/perf/builtin-sched.c > @@ -3267,20 +3264,34 @@ static int setup_color_cpus(struct perf_sched *sched) > > static int perf_sched__map(struct perf_sched *sched) > { > + int rc = -1; > + > if (setup_map_cpus(sched)) > - return -1; > + return rc; > > if (setup_color_pids(sched)) > - return -1; > + goto out_free_map_cpus; I think renaming the goto labels to what they will do, dropping a refcount, is more clear, i.e.: goto out_put_map_cpus; > > if (setup_color_cpus(sched)) > - return -1; > + goto out_free_color_pids; > > setup_pager(); > if (perf_sched__read_events(sched)) > - return -1; > + goto out_free_color_cpus; > + > + rc = 0; > print_bad_events(sched); > - return 0; > + > +out_free_color_cpus: > + perf_cpu_map__put(sched->map.color_cpus); > + > +out_free_color_pids: > + perf_thread_map__put(sched->map.color_pids); > + > +out_free_map_cpus: > + free(sched->map.comp_cpus); Please use: zfree(&sched->map.comp_cpus); > + perf_cpu_map__put(sched->map.cpus); > + return rc; > }