Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp935123lqo; Wed, 8 May 2024 22:37:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUADBKhmU5Yc2wwKDbsvz6tDAAxQK/oG+znvCrWTi1M2KKsDX61/zsE3gTR2k7nF7NaaJK7N+MNe1qMN+lsBUN52vsloQdbnaZs0aSAvA== X-Google-Smtp-Source: AGHT+IFlWuKfadXotb6y8o/QbwHjI7i99KEKtSrOyFkkqGhX3r0yEWRRFKPcCy5N/r3APkunSU6W X-Received: by 2002:a05:6214:e6b:b0:6a0:b3df:6601 with SMTP id 6a1803df08f44-6a1514bd1d2mr52153786d6.40.1715233056545; Wed, 08 May 2024 22:37:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715233056; cv=pass; d=google.com; s=arc-20160816; b=OmAEKZ8gHRGrUkIgX4kLJInK8yLb/+ib8LJICry7EHZNK8pFvYV6DL9OCZLg2t6D2Y rXMPt0/QMLDweSifYYsErwjDv3tsitIWKpp2nI8CS2u2//Zy9cf9QGzVrODX3JME2kfb bkd7DXEGQ4KbutR1TRFxgX+FHtI5hju1ybcdWIJJ6HKhWBFjrQK74Z+xn2dUyS/demXR VYtLO7J91o732bDu7Yief0231QGw/fJQ10Nm3F7TOPYJlthq7+Le6bziWuXaLuJFgz86 nbT5r0DaWLQQmuku8sreQvmj1qTL0JBN5Hmnzw9cl8wLavIBpXasrZCo8Qiw/g0x2al1 uRyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=wBu2+kmhThCqDtxFPgm069ky4hbWhjdpfaVsKApxqFU=; fh=K++ll+s+XvltKoAU/0oIovXrBPcrDK37d8ty8DtlrUs=; b=ODbppVKSK0WNgDdcDnt3xhxVEPJdHoxK3DaFAwobUHeF20nzHgpXk3x6t3aS9U3z0I UeHzm3o97XozEn/g7wkIIH0CHpIG0HKvxsmToMHIQSLifqZlyBGephKHPrG1Nldk6RUy wzwUOnVhJKBMIrtdfPOfIAsjNaI7xEAyKG5Kz2DBA0HbnCAhtkSt/vHHSGQlUSOrwbA6 rYI6qu0tVGxLapNQy/HOjPAKdDSUXFLl8/wwedaQyIu3zD+tZRAXMnBlfCplpph6RFwM k1SHJFsLKpWqJKfyvro5WreRj9HnjlQ3jC6MikjnPGgsE36gEUP1KzSqSIU0ZSMGfHPn 0oPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TF00JlCf; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-174167-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174167-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f2ee1fesi7300316d6.441.2024.05.08.22.37.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 22:37:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174167-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TF00JlCf; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-174167-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174167-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 473401C23276 for ; Thu, 9 May 2024 05:37:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 643A6149C71; Thu, 9 May 2024 05:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TF00JlCf" Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34E151494DF for ; Thu, 9 May 2024 05:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715232887; cv=none; b=m9TrGGO1A4k819v9CqbKf7XK3l5klbLT7udLbaxHN9TW1LwmohxGMq+4fEV9oErsronS97TN1Ha3Oujvj65nr6ZWzdgjGmv1HTWLNnJvmfnGM0hfcj92VVnYne0UU9w/qBVycgK8CfzNU9KUcqxZDNED7vrFBrwE3Q5rTwIEheA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715232887; c=relaxed/simple; bh=Yu/FlxoSX005QeAc+0Wxq9eAC3c4jYlWWcvVDh/Q3xk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Content-Type; b=rzx3KNudKUpDnw3sNAkjdNdcfVC+E78D4U3qlviLyuePAV/WfW+jhIWzDA6IAmVhkkOaBjHLSqCoadJ28t4ETww9YipD92xDqdRtO2Kmyx73dI0DZBzELIOKHhy1swC6Ffgk7HgThV99yDvbFKpIp9AA7W0XgDbEhzhLFBCrQr0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TF00JlCf; arc=none smtp.client-ip=209.85.160.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-439b1c72676so206941cf.1 for ; Wed, 08 May 2024 22:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715232885; x=1715837685; darn=vger.kernel.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=wBu2+kmhThCqDtxFPgm069ky4hbWhjdpfaVsKApxqFU=; b=TF00JlCfbTYkykR5n5zK6Y83QnzGSlMMvq9SnwPlDtdq1HwG+KumRzV/KdMUVksVKP 3VAyI6+KHJ84dbSsXQYm97Z2Wm3qsrjiRmNoPFAU/DrxpzxyRDgl2xgDUxmebrhPC/ZI J20a6B4SCdivE3YGzsnM0WZcm01CQXZZZCkHfnwEC8FjuTYhXHPdOE8JOoczIU3FXkzW vr9DuQ02n5Jmjmwf3yTHfNvgmLT76gdZrTHtB/E8NkdPOKI40gEPXIEqKrbPDWRbVizl L1M/Updb5NxdU9yZOQvJVXVlCLbQ3F6ZrJ/YBlWILUHBm6U3nyYK2l23AcPK57FWiRiB sRJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715232885; x=1715837685; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wBu2+kmhThCqDtxFPgm069ky4hbWhjdpfaVsKApxqFU=; b=w4uGYMgmIk4ZhBRpA9MQymmCWcN5NkvXEyIzaxrEYNv4d5Sx8isvvV5u03hJ/ZrrdI 8NPpfUhgs1JEiXEVVUcVYZPBpWrC2ypEiucOCuMOZOrTZFn0iMKB+xXDaXRWhJPut089 JRQ9Y//LpM7fvg5AiVb+acPI3Xbgwr7uVKQt1FuIqaOnQ2jQw5FpmLX3kqW+Sefx2Bit 4r/uhvCUXmsWS6vjLq4gnZzToQowRzb3ndsl95wQEZiVUVxAaObwV6qdpzj6W5Iykwt8 2paFJveDLwRmXZJBGqWgbxVb85sQaR5ddbtYSx7dN9egs/6kbJ5T6VfXE/RzzfjOWS3d WIXQ== X-Forwarded-Encrypted: i=1; AJvYcCW58oUu8BsLcGNbxGeVv29wUWXRs8kvUEoPRrMikF9vdr+fY7Cec3e1pPeANpMw6CXMf7a+31eDAB1f/gw5YdLTPc0/uBA3/kye3xv4 X-Gm-Message-State: AOJu0YzV1HUzzbfYUh+YWzIK/7VCKIO8isYAo1FinNSlm54OdpujIyRN IG2X+cfrcalJBJ7nTycYrpIqLxXVpnU+tGN72CT+VMHgH1UpNYWd2ZI0oEkkEmntLBMqW3QpCjN mXGCKfIKD+3WDqDNSmBfIe/HBmMpLwtSAye4i X-Received: by 2002:a05:622a:1c18:b0:43d:f69d:cf3a with SMTP id d75a77b69052e-43df69dd298mr568601cf.8.1715232884994; Wed, 08 May 2024 22:34:44 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240509052015.1914670-1-irogers@google.com> In-Reply-To: <20240509052015.1914670-1-irogers@google.com> From: Ian Rogers Date: Wed, 8 May 2024 22:34:33 -0700 Message-ID: Subject: Re: [PATCH v1] libsubcmd: Fix parse-options memory leak To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 8, 2024 at 10:20=E2=80=AFPM Ian Rogers wro= te: > > If a usage string is built in parse_options_subcommand, also free it. > > Signed-off-by: Ian Rogers Sorry, belated: Fixes: 901421a5bdf6 ("perf tools: Remove subcmd dependencies on strbuf") Thanks, Ian > --- > tools/lib/subcmd/parse-options.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-op= tions.c > index 9fa75943f2ed..d943d78b787e 100644 > --- a/tools/lib/subcmd/parse-options.c > +++ b/tools/lib/subcmd/parse-options.c > @@ -633,11 +633,10 @@ int parse_options_subcommand(int argc, const char *= *argv, const struct option *o > const char *const subcommands[], const char *usag= estr[], int flags) > { > struct parse_opt_ctx_t ctx; > + char *buf =3D NULL; > > /* build usage string if it's not provided */ > if (subcommands && !usagestr[0]) { > - char *buf =3D NULL; > - > astrcatf(&buf, "%s %s [] {", subcmd_config.exec_= name, argv[0]); > > for (int i =3D 0; subcommands[i]; i++) { > @@ -679,7 +678,10 @@ int parse_options_subcommand(int argc, const char **= argv, const struct option *o > astrcatf(&error_buf, "unknown switch `%c'", *ctx.= opt); > usage_with_options(usagestr, options); > } > - > + if (buf) { > + usagestr[0] =3D NULL; > + free(buf); > + } > return parse_options_end(&ctx); > } > > -- > 2.45.0.rc1.225.g2a3ae87e7f-goog >