[PATCH v2 10/26] perf header: Ensure bitmaps are freed
Ian Rogers
irogers at google.com
Thu Jun 8 16:28:07 PDT 2023
memory_node bitmaps need a bitmap_free to avoid memory leaks. Caught
by leak sanitizer.
Signed-off-by: Ian Rogers <irogers at google.com>
---
tools/perf/util/header.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index d85b39079c31..3db7c1fae71e 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1389,6 +1389,14 @@ static int memory_node__read(struct memory_node *n, unsigned long idx)
return 0;
}
+static void memory_node__delete_nodes(struct memory_node *nodesp, u64 cnt)
+{
+ for (u64 i = 0; i < cnt; i++)
+ bitmap_free(nodesp[i].set);
+
+ free(nodesp);
+}
+
static int memory_node__sort(const void *a, const void *b)
{
const struct memory_node *na = a;
@@ -1449,7 +1457,7 @@ static int build_mem_topology(struct memory_node **nodesp, u64 *cntp)
*nodesp = nodes;
qsort(nodes, cnt, sizeof(nodes[0]), memory_node__sort);
} else
- free(nodes);
+ memory_node__delete_nodes(nodes, cnt);
return ret;
}
@@ -1516,7 +1524,7 @@ static int write_mem_topology(struct feat_fd *ff __maybe_unused,
}
out:
- free(nodes);
+ memory_node__delete_nodes(nodes, nr);
return ret;
}
--
2.41.0.162.gfafddb0af9-goog
More information about the linux-arm-kernel
mailing list