Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp627980lqp; Wed, 22 May 2024 14:57:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKz7G7gCNeeP7l4QyrpChiYYitk0ittK4y6erSyfrMx1fkxTcVrvuYp5n1lHjue0Q0jrFhMhLG/cyP6VWlzSrwBIfZN8ch1efuu+Uh3w== X-Google-Smtp-Source: AGHT+IHiaZ2ynZtyICYLiFiC77CjOyp45sfQ1LEPvCQQFqDhLL5pcC+9+aCBJXz+Xa6MBa7otcyz X-Received: by 2002:a05:6358:7689:b0:186:3c3:b415 with SMTP id e5c5f4694b2df-1979213188emr499293655d.20.1716415058936; Wed, 22 May 2024 14:57:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716415058; cv=pass; d=google.com; s=arc-20160816; b=LohaofKrFmRSfJcKfK4sbF2v8jFfbKVxuvnAn2s3MVIRNdU8Au/Hy4VZf1GvXyE5nT uBeAPrQXzJ9lgngTGZHA5lWWTACqESanB1wulSWWin8uEgbwpZ1W3bX4kQCiOSOBZfxv SP48GWRhxtrTVKySKhByjblNxp71wgES6sPB835G3Q0hNQYRN5+sq+G+a5QHJ4PsgpqE 5Erkm2Z24u4vujdFcVlqKayrIzculcYvGlMOSlpWSLnVbZDgGrlQYCs0ua/l9WR7og9s elv5Em2QtQEiEnjEfmmDqmdqbQY32Syzbc7AVWJBzIFIc070bfcdA69tX4pDgQlPQhvs foOg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+9BK5ugeFXewMt8+vjnIxESHNBgFvCJRoFvDzbd0fXs=; fh=+1J0V14dKjMi8h4q7hKoOukbS74/BCx2naK7yok440s=; b=aj+Le1miG35s9oGW9/NrbP4IJXZt3WyUNZgTL/+24u0lM6GYt4BxYg5UMliYrF2j3q QaCcAeuH0H4itRoxrliBdd/kFLD9Tm/Ea79uZIkB87cWJ+fvXqgcdSL4MJVaOxyT9mzh JvPTJkEFKw3XGz3PADrfYcHkZvxdHDD0Vns8O0Rhrpn77jJ/z80HdZ7fSyiSij9UfdsK jSXfT7H/c4cl6DEp/NKdCLVri5Dy5HVfP8wAt1CX8shzO7iJie+RgIga0+WjkWTyU7WQ CpLWKbxrU0vZ3xn2x6rSgpsPlodF+/UeijnUkvQsGahPVbbjTIIDSJsE7I7b+8BVHUmI ZOpA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tXosBCvd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-186754-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186754-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2a72d8asi7598608b3a.27.2024.05.22.14.57.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 14:57:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-186754-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tXosBCvd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-186754-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186754-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 8366D28209A for ; Wed, 22 May 2024 21:57:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8032B148840; Wed, 22 May 2024 21:56:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tXosBCvd" 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 68641148319; Wed, 22 May 2024 21:56:21 +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=1716414981; cv=none; b=s7bNhnllA7Xr5znOSjVvxSnYU54IrQ4WYSZXAzb2P6Tawv5P6ZBn8VAFRF1bfWstQVxKow8IipncApdI8Sx/GFcmZSjJA1iEUIwF0+L22lldLM/XXXGOxxMxVa3n+idBsfpztGcp0hS3B/OuH+v2bVHn8J+ZDdLlFMKDsar30d0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716414981; c=relaxed/simple; bh=g2LbaED2hm8TXq5ygOtsvI8bLNm/2ntxIyuanbuwyZ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=szpx40QkLWDGR11XlY1ziEFY09C6rr+eWzrjhk270ksTmI3mhaYOhJ0xQIEv0mPtIGhJpwy7aPhDbkzk+jJb0m6fP0+650OTWBcgMfGFajqWAUR6xJN6ZsVNOhW+8M19R17jRFKImNF/33AWV8vNtyErIDF9BwvEHqziZcUoKxs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tXosBCvd; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7921BC32782; Wed, 22 May 2024 21:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716414980; bh=g2LbaED2hm8TXq5ygOtsvI8bLNm/2ntxIyuanbuwyZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tXosBCvdU/fmRy6bqCBGtzQyBuZKubysDv6ibov1FWnPsNPqWutySDKYOTT+lU+sm Ha3GQY2wuNpPrTRrBibpKrBrRxkHqXfK3pvg8CTelvO1txLTTLAt/+kY9SG86JCLiO JbbNVV8/5IlJOEHzenYgn6RffVfL2FMu2o6IX6yyNuabLHBPRFk5paGIExoc63xkcL Eo4VFXMXAiQafUbhwGnVttz7+C1mfzyYiUtCfj+9Nw4i95zNT9QzLSPy2QT7+5r9YP 57CHJru5Gi3Jks37tzlWb1EDMzr1A/KynvteO2l5uZdn/7JvFMnfEYds5p3xUnQdky oFiFDaXD0cWQQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, KP Singh , Stephane Eranian , Song Liu , bpf@vger.kernel.org Subject: [PATCH 5/6] perf record: Fix a potential error handling issue Date: Wed, 22 May 2024 14:56:15 -0700 Message-ID: <20240522215616.762195-6-namhyung@kernel.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240522215616.762195-1-namhyung@kernel.org> References: <20240522215616.762195-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The evlist is allocated at the beginning of cmd_record(). Also free-ing thread masks should be paired with record__init_thread_masks() which is called right before __cmd_record(). Let's change the order of these functions to release the resources correctly in case of errors. This is maybe fine as the process exits, but it might be a problem if it manages some system-wide resources that live longer than the process. Signed-off-by: Namhyung Kim --- tools/perf/builtin-record.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 8ec0b1607603..3a5a24dec356 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -4258,13 +4258,13 @@ int cmd_record(int argc, const char **argv) err = __cmd_record(&record, argc, argv); out: - evlist__delete(rec->evlist); + record__free_thread_masks(rec, rec->nr_threads); + rec->nr_threads = 0; symbol__exit(); auxtrace_record__free(rec->itr); out_opts: - record__free_thread_masks(rec, rec->nr_threads); - rec->nr_threads = 0; evlist__close_control(rec->opts.ctl_fd, rec->opts.ctl_fd_ack, &rec->opts.ctl_fd_close); + evlist__delete(rec->evlist); return err; } -- 2.45.1.288.g0e0cd299f1-goog