diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c index 7ffabee4004f..82079e7660ea 100644 --- a/sys/dev/hwpmc/hwpmc_mod.c +++ b/sys/dev/hwpmc/hwpmc_mod.c @@ -4367,6 +4367,12 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) break; error = copyout(&pa, arg, sizeof(pa)); + /* + * The caller never learns the ID of an unpublished PMC; do + * not leave it (and the row it holds) behind. + */ + if (error != 0) + (void)pmc_do_op_pmcrelease(pa.pm_pmcid); } break;