Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp262984rdh; Sat, 23 Sep 2023 09:16:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPNeekNz9gbZZe4vccgiOlpjh5ieC5INyGM7U1I+9rpUumY7zkAPATpYAkfLZ00lEwQppL X-Received: by 2002:a17:90a:ec04:b0:276:b87d:2324 with SMTP id l4-20020a17090aec0400b00276b87d2324mr2474070pjy.38.1695485769601; Sat, 23 Sep 2023 09:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695485769; cv=none; d=google.com; s=arc-20160816; b=QcE/3mv/u+/7b00lprrz0XnSDLldw2VX9N55HtjBhP/TsGc+2m9BTuU3+pTZBA7R6V 3xyW215+eCdrEkyMJ7youu7E4zv0dtoTFdAllhOTegKFJ9qS+nQvZ4gAXawTU2VcLklM 2UZBP7Wc0xZCJxWvGWWebVFCCAfvWCCaKJOI52A2KEIuOCrBQE4+0xhav82IhtMuDLK2 O6pQusOfdHO644KARefvs9M6FMeklhltWMP8ZsofdarL/tIadt4ubDqUsbRxLYvQGAD+ 2Yy0U5EP9+124ETmRCMG2cAWRRtOz//oZG125lagd6Hht5cO5ezOuv6hTMBlpRJAoVXw cShA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=lP0CZzDRsMehpIV0W6qVRwyai9STrfRNe8AVt5V6Hgk=; fh=wFFPmy5oZx9gf1iTxJ8OPAx6+fLFvzTVx6T3ogPJNVM=; b=zC2piEY/pTM/20xJgkvbeVBbQVWNQgeohCbKyA0QpdQKEjHVMgv0+RMsb3Ce4Go7PA IfFao4ps0cZyPDF7IPT32umzi5EkHq7gGGbu6lnADHNY9aDVak5ceqTwOS1klYx7gPCz Eu4cWfZnQxxBAXiCWdQSwX3E3/TFTw3uH3UX43pmvUAp61AAJ+guw2Qm19qYsKJAxoOQ tKLma6BoDeHt32koV2icZRROsQXDmFXhrWdk3KFx19ZppGGDOLUNxCF2lpjBI8/qEK6W SFHrEE5BmExlknqHei3Y6LwIJNudqv9Tf+4wHWHXjxKItdlGgmy46g1PsQ/1NiLZ2u9X fQYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=idybEtf6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id ld12-20020a170902facc00b001c3671d3151si6074022plb.92.2023.09.23.09.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 09:16:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=idybEtf6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0DA4283C6AE2; Fri, 22 Sep 2023 22:37:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230164AbjIWFhH (ORCPT + 99 others); Sat, 23 Sep 2023 01:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbjIWFgb (ORCPT ); Sat, 23 Sep 2023 01:36:31 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80A3D170D for ; Fri, 22 Sep 2023 22:36:07 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d81841ef79bso4933575276.1 for ; Fri, 22 Sep 2023 22:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695447366; x=1696052166; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=lP0CZzDRsMehpIV0W6qVRwyai9STrfRNe8AVt5V6Hgk=; b=idybEtf6E9zqATWwOS3c4cWkW0lURrMrDuD/rX+I8fp3cJWjLPO2CkfrguM8a+uk3C IQjor63Wj63pgny1pbWYcvtP9qAjknFXLBG8yDKNPhqWwSYPO1qeR/JhILzKzFzmJX2/ slTEu72lGHJOm4AVZxdw3LA00ARizD2ZrAhA54YFHTnKzgmw8+MwGa6reNqiKpQa/KL8 wO8MVJufRINlovSmzKP5pcNCS1/jjQJxASIDwe6ZB8Q0ICl880Lr8K2HMjs6IX20+DZh 3ohd5H4290LLl0PNzdcmkjtOIzG6b0j7gyWGkc4x/KIxVcrBl3+JKNb7MqQkk8Cc9GwQ 9qaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695447366; x=1696052166; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lP0CZzDRsMehpIV0W6qVRwyai9STrfRNe8AVt5V6Hgk=; b=I9AHAHHJwmuuBTuxR+mBYyL5CrlgE8xaBbG+zH5Ejp/uWxbA0pL/6lfoj938eT6sYi MI/GW+l/DQAUsDzQxINJXz7phq1ztQUJb+xOgf6pbo9G+BocNXrmTrkxb2vmbJnvNu0m s1QH4qLoyHWnCKkzmiLNWB9/QDEEWdya2LtpMh6MGJ5EecJhcgS9aBtk/FlX7I65ob6f +OCIZVeZvWVxD5Q/h3aGDDHS67a6QZuFVMYts11OxF48IdWs62ms0YarDNSlwTKevvwM Spf0HpQZ+lfTdCOJhK4NidLF/VJY6BguitZ2AIMIitgIN8TxTVGWL2R2oC/lGMNKAqGx wzBw== X-Gm-Message-State: AOJu0YzR1mnl/hzGHUoFl1Eo9XrSPh+MRChXumxqbp8rSZ2aInnMd/UX uhtEJAI4f+epxfc9CguDMSooQYuDBnm2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a376:2908:1c75:ff78]) (user=irogers job=sendgmr) by 2002:a25:403:0:b0:d7a:bfcf:2d7 with SMTP id 3-20020a250403000000b00d7abfcf02d7mr11997ybe.6.1695447366091; Fri, 22 Sep 2023 22:36:06 -0700 (PDT) Date: Fri, 22 Sep 2023 22:35:10 -0700 In-Reply-To: <20230923053515.535607-1-irogers@google.com> Message-Id: <20230923053515.535607-14-irogers@google.com> Mime-Version: 1.0 References: <20230923053515.535607-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Subject: [PATCH v1 13/18] perf svghelper: Avoid memory leak From: Ian Rogers To: Nathan Chancellor , Nick Desaulniers , Tom Rix , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Yicong Yang , Jonathan Cameron , Yang Jihong , Kan Liang , Ming Wang , Huacai Chen , Sean Christopherson , K Prateek Nayak , Yanteng Si , Yuan Can , Ravi Bangoria , James Clark , Paolo Bonzini , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 22 Sep 2023 22:37:07 -0700 (PDT) On success path the sib_core and sib_thr values weren't being freed. Detected by clang-tidy. Signed-off-by: Ian Rogers --- tools/perf/builtin-lock.c | 1 + tools/perf/util/svghelper.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index d4b22313e5fc..1b40b00c9563 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -2463,6 +2463,7 @@ static int parse_call_stack(const struct option *opt __maybe_unused, const char entry = malloc(sizeof(*entry) + strlen(tok) + 1); if (entry == NULL) { pr_err("Memory allocation failure\n"); + free(s); return -1; } diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index 0e4dc31c6c9c..1892e9b6aa7f 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -754,6 +754,7 @@ int svg_build_topology_map(struct perf_env *env) int i, nr_cpus; struct topology t; char *sib_core, *sib_thr; + int ret = -1; nr_cpus = min(env->nr_cpus_online, MAX_NR_CPUS); @@ -799,11 +800,11 @@ int svg_build_topology_map(struct perf_env *env) scan_core_topology(topology_map, &t, nr_cpus); - return 0; + ret = 0; exit: zfree(&t.sib_core); zfree(&t.sib_thr); - return -1; + return ret; } -- 2.42.0.515.g380fc7ccd1-goog