git: 9c0a2d522f3a - main - hwpmc_armv7: plug memory leak
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 03 Aug 2023 14:13:22 UTC
The branch main has been updated by mhorne:
URL: https://cgit.FreeBSD.org/src/commit/?id=9c0a2d522f3a18fc795a7dd6266d2be2aff4b084
commit 9c0a2d522f3a18fc795a7dd6266d2be2aff4b084
Author: Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-08-03 14:10:26 +0000
Commit: Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-08-03 14:13:10 +0000
hwpmc_armv7: 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/D41269
---
sys/dev/hwpmc/hwpmc_armv7.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/sys/dev/hwpmc/hwpmc_armv7.c b/sys/dev/hwpmc/hwpmc_armv7.c
index 89cb27457bd2..6275e0f98c8b 100644
--- a/sys/dev/hwpmc/hwpmc_armv7.c
+++ b/sys/dev/hwpmc/hwpmc_armv7.c
@@ -414,7 +414,7 @@ armv7_pcpu_init(struct pmc_mdep *md, int cpu)
KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
("[armv7,%d] wrong cpu number %d", __LINE__, cpu));
- PMCDBG1(MDP, INI, 1, "armv7-init cpu=%d", cpu);
+ PMCDBG0(MDP, INI, 1, "armv7-pcpu-init");
armv7_pcpu[cpu] = pac = malloc(sizeof(struct armv7_cpu), M_PMC,
M_WAITOK|M_ZERO);
@@ -450,6 +450,8 @@ armv7_pcpu_fini(struct pmc_mdep *md, int cpu)
{
uint32_t pmnc;
+ PMCDBG0(MDP, INI, 1, "armv7-pcpu-fini");
+
pmnc = cp15_pmcr_get();
pmnc &= ~ARMV7_PMNC_ENABLE;
cp15_pmcr_set(pmnc);
@@ -459,6 +461,10 @@ armv7_pcpu_fini(struct pmc_mdep *md, int cpu)
cp15_pminten_clr(pmnc);
cp15_pmovsr_set(pmnc);
+ free(armv7_pcpu[cpu]->pc_armv7pmcs, M_PMC);
+ free(armv7_pcpu[cpu], M_PMC);
+ armv7_pcpu[cpu] = NULL;
+
return 0;
}
@@ -529,5 +535,7 @@ pmc_armv7_initialize(void)
void
pmc_armv7_finalize(struct pmc_mdep *md)
{
+ PMCDBG0(MDP, INI, 1, "armv7-finalize");
+ free(armv7_pcpu, M_PMC);
}