Skip to content

Commit 601b05c

Browse files
chaudronAlexei Starovoitov
authored andcommitted
libbpf: Fix perf_buffer__free() API for sparse allocs
In case the cpu_bufs are sparsely allocated they are not all free'ed. These changes will fix this. Fixes: fb84b82 ("libbpf: add perf buffer API") Signed-off-by: Eelco Chaudron <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/159056888305.330763.9684536967379110349.stgit@ebuild Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent ee103e9 commit 601b05c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8137,9 +8137,12 @@ void perf_buffer__free(struct perf_buffer *pb)
81378137
if (!pb)
81388138
return;
81398139
if (pb->cpu_bufs) {
8140-
for (i = 0; i < pb->cpu_cnt && pb->cpu_bufs[i]; i++) {
8140+
for (i = 0; i < pb->cpu_cnt; i++) {
81418141
struct perf_cpu_buf *cpu_buf = pb->cpu_bufs[i];
81428142

8143+
if (!cpu_buf)
8144+
continue;
8145+
81438146
bpf_map_delete_elem(pb->map_fd, &cpu_buf->map_key);
81448147
perf_buffer__free_cpu_buf(pb, cpu_buf);
81458148
}

0 commit comments

Comments
 (0)