[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230923053515.535607-5-irogers@google.com>
Date: Fri, 22 Sep 2023 22:35:01 -0700
From: Ian Rogers <irogers@...gle.com>
To: Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Tom Rix <trix@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Yicong Yang <yangyicong@...ilicon.com>,
Jonathan Cameron <jonathan.cameron@...wei.com>,
Yang Jihong <yangjihong1@...wei.com>,
Kan Liang <kan.liang@...ux.intel.com>,
Ming Wang <wangming01@...ngson.cn>,
Huacai Chen <chenhuacai@...nel.org>,
Sean Christopherson <seanjc@...gle.com>,
K Prateek Nayak <kprateek.nayak@....com>,
Yanteng Si <siyanteng@...ngson.cn>,
Yuan Can <yuancan@...wei.com>,
Ravi Bangoria <ravi.bangoria@....com>,
James Clark <james.clark@....com>,
Paolo Bonzini <pbonzini@...hat.com>, llvm@...ts.linux.dev,
linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org,
bpf@...r.kernel.org
Subject: [PATCH v1 04/18] perf hisi-ptt: Fix potential memory leak
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'
```
Signed-off-by: Ian Rogers <irogers@...gle.com>
---
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.515.g380fc7ccd1-goog
Powered by blists - more mailing lists