Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp531431lqo; Fri, 10 May 2024 07:17:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3kBlIfdg/Kvks4RwssJW/rThzqvJDtWjWOlPhX2c3iQZvrPjBZvnE3ZI5FzF1/iAmB/CXZ+yjQWOesYzfQqADA954eNY/NvmIjrnHKQ== X-Google-Smtp-Source: AGHT+IE/YvZjkrIgZlFcIhT8ZpzTSNe1+nJSps0mkEqX+M5DQ5BSqhvLhsbBPJ3d5xj+A5cLOvpK X-Received: by 2002:a05:6214:5bc2:b0:6a0:b6a9:39b0 with SMTP id 6a1803df08f44-6a168242d87mr33384046d6.59.1715350637152; Fri, 10 May 2024 07:17:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715350637; cv=pass; d=google.com; s=arc-20160816; b=qyxUtDuWaogaFW3FeytRvOluWCleySUsfvtTCASwtQrunJIQfZetgso5q1/VwqzS7s qtxQTR3WYBMnNPtYaLXpnb+dwiCfOH2NLHvbJBK2dEVHQMVHftCyxw00Ia1MvPAKfvAo KgkkXr6GuD4uhnD4rvmZgMHERitVXpyfzoLPnz9bUbJksfN8Jbzbtynh84mkK1KKyozr RB/maYV7PGxwAwEUi3BLVckgoTSMM6zRT0056TyhDwnJZg1MJUOVAOUIFJm52Wod956K UuUlHdluQDopKlqnGqXyEX9d3vRMRQ/rNMz2JkSYrdZVOwIfDCk2CyE4UMkiG5Nw14HO xCzw== 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=frSOU7jcorI4Ai9+ijqqb6aF7U7AjETbYrEMp445Vc8=; fh=rJAlIgBClQY8i6UBNlznPkzFQuxonBg32VMUk838xnU=; b=ikWRtB0y0vI2WuBgzN14Z9H3mK/OccTTQUlbPaicPzjnb2ABe02q3stfR9CscrJ8Bt ZNHL23sdeCT81N32KtzwhVrP+iEeF6nIOO/CFFqhm6CWMOhKLNgkbAa0sHJfkORTyMom QNKWCQN1VveMFJQShHIDG2py5HVkCwuKnqvTVp5cu6h8rjFI07FLYDgrq9jNMJQJ6dG5 lmGmxf2Po8ResGxV83fbn8Z7QBKDZvHbk9D2bVvUaCWwdTv3jOqzzi6imm/OCAUhMJX+ pCJ+MmK22AlrshSXFsQbU2ATW2Yp6dYzDXye9S1yDpzwpHUxnNpqcbDgwMCiAcCWwRDT 7pwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q+ocGzjW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-175877-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175877-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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-6a15f1d72c6si37924386d6.57.2024.05.10.07.17.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 07:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175877-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=@kernel.org header.s=k20201202 header.b=q+ocGzjW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-175877-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175877-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A50A41C2191D for ; Fri, 10 May 2024 14:17:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02EE1135A6D; Fri, 10 May 2024 14:17:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q+ocGzjW" 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 23F873F8D1; Fri, 10 May 2024 14:17:03 +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=1715350624; cv=none; b=Ao3tAUELDaR2TTNb2mbVtDkF5VTBf3EkZWd7+qUdp0787FoQgfYqLv0M9fN4NiUxFo/GFEjt4Y/bMjbBJ2RxGsIuEK01zVOcJFZuZsvYqCW/QYghziwYhRyhwcr36fE2jlvCkieuVHuq8CcLzVIVIM2duRnqId1V9rqu3KJsS/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715350624; c=relaxed/simple; bh=V450PsVFKYuLz/CjQ5KVeg3wqYL5FGkcrDqCeTiCgww=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QY2TdYyAnLmXi5DcKSY58daNSKxGRPgSs3eMqXt3o/uupqz830QQYlpZPO742DejStKP7dmxAJYJoywRCa0vbohpEZRwtZty8PM1o0DHYBmqpvMNQsZpwCw/2xUjCKZo1QWPBKkg+1wcJLR0cC2m1MUNd3Yc74NFUpdUgALMTUM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q+ocGzjW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21174C113CC; Fri, 10 May 2024 14:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715350623; bh=V450PsVFKYuLz/CjQ5KVeg3wqYL5FGkcrDqCeTiCgww=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=q+ocGzjWS4vHjZml0C7t25uCD7NfD9xoTBfNCQwEMwNXA2c5JhqEQOTWTP7bjW54C gDQsceixmbfHBaaqZFd5eS0DqcbxSkLS5dET3l+EDUION8wB39IdzngRyxhlfZy4aM OmxWcDVFsTL0SsjBJn7D1rg146sx+dtVjslXIzwaVr/5AmoZS5cdb/BCctZBttNu1W qxZi92HgtWPEsIwQJ352XeQGTMS7QszVM2VJsacB0OhLgGo23lsiD4pa1LZ+ERXRii FtmVabvdSCn11qll6YcaTTE4DAZBaNAmJc2XEE9B42lEzGfVjp9BRgM21szFbec2eS oHmqybYxI9PEw== Date: Fri, 10 May 2024 11:17:00 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH v1] libsubcmd: Fix parse-options memory leak Message-ID: References: <20240509052015.1914670-1-irogers@google.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: <20240509052015.1914670-1-irogers@google.com> On Wed, May 08, 2024 at 10:20:15PM -0700, Ian Rogers wrote: > If a usage string is built in parse_options_subcommand, also free it. Thanks, applied to perf-tools-next, - Arnaldo > Signed-off-by: Ian Rogers > --- > 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-options.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 *usagestr[], int flags) > { > struct parse_opt_ctx_t ctx; > + char *buf = NULL; > > /* build usage string if it's not provided */ > if (subcommands && !usagestr[0]) { > - char *buf = NULL; > - > astrcatf(&buf, "%s %s [] {", subcmd_config.exec_name, argv[0]); > > for (int i = 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] = NULL; > + free(buf); > + } > return parse_options_end(&ctx); > } > > -- > 2.45.0.rc1.225.g2a3ae87e7f-goog