The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=8bdceaecabd91ce5ed23646d91cef878681e19d6
commit 8bdceaecabd91ce5ed23646d91cef878681e19d6 Author: Mitchell Horne <[email protected]> AuthorDate: 2023-08-03 14:09:48 +0000 Commit: Mitchell Horne <[email protected]> CommitDate: 2023-08-03 14:13:03 +0000 hwpmc_arm64: plug memory leak Free allocated per-CPU structures in the pcpu_fini and finalize methods. While here, add debug trace entries to these methods. Reviewed by: jkoshy, andrew MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41268 --- sys/dev/hwpmc/hwpmc_arm64.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sys/dev/hwpmc/hwpmc_arm64.c b/sys/dev/hwpmc/hwpmc_arm64.c index bbd3edf84ea0..90a35456feb7 100644 --- a/sys/dev/hwpmc/hwpmc_arm64.c +++ b/sys/dev/hwpmc/hwpmc_arm64.c @@ -450,7 +450,7 @@ arm64_pcpu_init(struct pmc_mdep *md, int cpu) KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[arm64,%d] wrong cpu number %d", __LINE__, cpu)); - PMCDBG1(MDP, INI, 1, "arm64-init cpu=%d", cpu); + PMCDBG0(MDP, INI, 1, "arm64-pcpu-init"); arm64_pcpu[cpu] = pac = malloc(sizeof(struct arm64_cpu), M_PMC, M_WAITOK | M_ZERO); @@ -491,10 +491,16 @@ arm64_pcpu_fini(struct pmc_mdep *md, int cpu) { uint32_t pmcr; + PMCDBG0(MDP, INI, 1, "arm64-pcpu-fini"); + pmcr = arm64_pmcr_read(); pmcr &= ~PMCR_E; arm64_pmcr_write(pmcr); + free(arm64_pcpu[cpu]->pc_arm64pmcs, M_PMC); + free(arm64_pcpu[cpu], M_PMC); + arm64_pcpu[cpu] = NULL; + return (0); } @@ -605,5 +611,7 @@ pmc_arm64_initialize(void) void pmc_arm64_finalize(struct pmc_mdep *md) { + PMCDBG0(MDP, INI, 1, "arm64-finalize"); + free(arm64_pcpu, M_PMC); }
