Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1699718rdb; Sun, 8 Oct 2023 22:42:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF46xCkjtyfgDDADyQdAmtpiMZUWiNFP6u9uFTGgWLA4AnvBdx8Yq4jfxSgg46RCs2qdAtQ X-Received: by 2002:a05:6a20:144c:b0:13c:ca8b:7e29 with SMTP id a12-20020a056a20144c00b0013cca8b7e29mr17469036pzi.12.1696830127015; Sun, 08 Oct 2023 22:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696830127; cv=none; d=google.com; s=arc-20160816; b=CdDz2swyYovFbGjTCU2g44QDNpQVgocSMS8i6UKntW9+dZZJuMUV80xDN+tcGNHxlx bj7S6RPvUWAmS35C9NnMJRNwpEhjn8Ihq5+5410g4TY8q13G/GbOBhtjpNYxDLHEZren q2aVvDRzuMFTSrDqOU0VSrQ+vq5tyZqle2CBsb7jOUAkKqHMgOWPfWkN9wA6pj66Vgf9 ocfpToLlm4IrYa1hqUTbKzDmFcqLXfnhxI0+BKBf2J0Nq7dzYnMH2pFw/wPWnj+3xYyD UoOwu/sf6K0KvmmVfvBYIDHQURuGxGTIGQjAyyMBaFgmvMm0++AIl6PpzA1+k91kyCxP QQ8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=4bwrRDRYXEv5Ngil2iTxo5opf6F7zsNUan/4S3HdRY0=; fh=MbKHNh6f/dPQmT3ryA7zZy0QPi8HYeNocTgtdgDnzoU=; b=y0KbxMZXH5B2SWzG4mWFs5V3beTaPp3taEIWnMI3kjJ3RZYoMLQOsotFty8iMY4zrA stcePYGqcc3JMdtN0Pz0Krs8VgB3wHWd6WTDf5I4B0yBwKUDBYyL7fcWJtYPheymKgzF cbsOj+4hiXrICi4Kn/AuEEmjTTc0K5Gr+UZ5JnM5QkTeTdrwdoPrSJ908AJzTRDiLYPM wuWIGNYgZuLnQCKlrQ2L8d/gxnzLRuknTfwFEnZXKSG22h4bgGKXiYuUiqkvn2UOUvHF VirI1ZSPBukRgO3KfWlfaDlXJOn60rw13NRqAPCkNrC0hgOu3qTsfK7Z24nURDWcb+mj 3HWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id s16-20020a170902ea1000b001bbc61fedafsi5951981plg.422.2023.10.08.22.42.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 22:42:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 2694C8049118; Sun, 8 Oct 2023 22:42:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345129AbjJIFly convert rfc822-to-8bit (ORCPT + 99 others); Mon, 9 Oct 2023 01:41:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345049AbjJIFlx (ORCPT ); Mon, 9 Oct 2023 01:41:53 -0400 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00216A4; Sun, 8 Oct 2023 22:41:51 -0700 (PDT) Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-27b0d0c0ba0so3182964a91.1; Sun, 08 Oct 2023 22:41:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696830111; x=1697434911; h=content-transfer-encoding:cc: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=2RX7tLaR5cxlZGvCt5yVuBVmtnOHN5nH9geYt6ELosk=; b=RbIkAhdpuztmdKVcGKcTgLthZGnxPL+FRcI0hUinWt9wr4eseRCbUXHPwmxBfJnbJm APbrSyZNxyFpVNvjfJA7sjyfeX7N39m6ZkG9tLgQDQDEpMlL1J7CVGVuRh76+/S9kU+C c/Y7k4cYW5DULmDssO8L7FpAPJ2tfJLdkH2CK6KeX8dm/Z6yR1i/xCTDuQHqH1tTPO8x Hj3sA5CirILXI2vBP1D+ze4eD81nzIdjvQYLJYZgca7o5UP0So95pvHeS/j64+Qu93og XvlfkNnlxCzneSILTpmCCxscXGPmUTnTSRG9svx/2zzrEicsGX25/3DfdAHLWcHTVPw3 gEhQ== X-Gm-Message-State: AOJu0YyC9H2Yv2J/tDcQm9wsy5oIeZOFOD7Q8Lr9fIfxFifXoXb/HYqV JypJSwxYnOhnfbr4qbRqIlB3XiNnaVkffYLF2Pc= X-Received: by 2002:a17:90b:3e87:b0:274:755b:63b8 with SMTP id rj7-20020a17090b3e8700b00274755b63b8mr14069468pjb.43.1696830111351; Sun, 08 Oct 2023 22:41:51 -0700 (PDT) MIME-Version: 1.0 References: <20231005230851.3666908-1-irogers@google.com> <20231005230851.3666908-5-irogers@google.com> In-Reply-To: <20231005230851.3666908-5-irogers@google.com> From: Namhyung Kim Date: Sun, 8 Oct 2023 22:41:40 -0700 Message-ID: Subject: Re: [PATCH v2 04/18] perf hisi-ptt: Fix potential memory leak To: Ian Rogers Cc: Nathan Chancellor , Nick Desaulniers , Tom Rix , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , 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 , 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" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=2.6 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Sun, 08 Oct 2023 22:42:02 -0700 (PDT) X-Spam-Level: ** On Thu, Oct 5, 2023 at 4:09 PM Ian Rogers wrote: > > Fix clang-tidy found potential memory leak and unread value: > ``` > tools/perf/util/hisi-ptt.c:108:3: warning: Value stored to 'data_offset' is never read [clang-analyzer-deadcode.DeadStores] > data_offset = 0; > ^ ~ > tools/perf/util/hisi-ptt.c:108:3: note: Value stored to 'data_offset' is never read > data_offset = 0; > ^ ~ > tools/perf/util/hisi-ptt.c:112:12: warning: Potential leak of memory pointed to by 'data' [clang-analyzer-unix.Malloc] > return -errno; > ^ > /usr/include/errno.h:38:18: note: expanded from macro 'errno' > ^ > tools/perf/util/hisi-ptt.c:100:15: note: Memory is allocated > void *data = malloc(size); > ^~~~~~~~~~~~ > tools/perf/util/hisi-ptt.c:104:6: note: Assuming 'data' is non-null > if (!data) > ^~~~~ > tools/perf/util/hisi-ptt.c:104:2: note: Taking false branch > if (!data) > ^ > tools/perf/util/hisi-ptt.c:107:6: note: Assuming the condition is false > if (perf_data__is_pipe(session->data)) { > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > tools/perf/util/hisi-ptt.c:107:2: note: Taking false branch > if (perf_data__is_pipe(session->data)) { > ^ > tools/perf/util/hisi-ptt.c:111:7: note: Assuming the condition is true > if (data_offset == -1) > ^~~~~~~~~~~~~~~~~ > tools/perf/util/hisi-ptt.c:111:3: note: Taking true branch > if (data_offset == -1) > ^ > tools/perf/util/hisi-ptt.c:112:12: note: Potential leak of memory pointed to by 'data' > return -errno; > ^ > /usr/include/errno.h:38:18: note: expanded from macro 'errno' > ``` We already have https://lore.kernel.org/r/20230930072719.1267784-1-visitorckw@gmail.com Thanks, Namhyung > > Signed-off-by: Ian Rogers > --- > tools/perf/util/hisi-ptt.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/tools/perf/util/hisi-ptt.c b/tools/perf/util/hisi-ptt.c > index 45b614bb73bf..ea297329c526 100644 > --- a/tools/perf/util/hisi-ptt.c > +++ b/tools/perf/util/hisi-ptt.c > @@ -98,18 +98,18 @@ static int hisi_ptt_process_auxtrace_event(struct perf_session *session, > int fd = perf_data__fd(session->data); > int size = event->auxtrace.size; > void *data = malloc(size); > - off_t data_offset; > int err; > > if (!data) > return -errno; > > - if (perf_data__is_pipe(session->data)) { > - data_offset = 0; > - } else { > - data_offset = lseek(fd, 0, SEEK_CUR); > - if (data_offset == -1) > + if (!perf_data__is_pipe(session->data)) { > + off_t data_offset = lseek(fd, 0, SEEK_CUR); > + > + if (data_offset == -1) { > + free(data); > return -errno; > + } > } > > err = readn(fd, data, size); > -- > 2.42.0.609.gbb76f46606-goog >