diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c --- a/sys/dev/hwpmc/hwpmc_mod.c +++ b/sys/dev/hwpmc/hwpmc_mod.c @@ -4989,13 +4989,13 @@ } PMC_EPOCH_EXIT(); - if (!is_using_hwpmcs) - return; - PMC_GET_SX_XLOCK(); PMCDBG3(PRC,EXT,1,"process-exit proc=%p (%d, %s)", p, p->p_pid, p->p_comm); + if (!is_using_hwpmcs) + goto out; + /* * Since this code is invoked by the last thread in an exiting process, * we would have context switched IN at some prior point. However, with @@ -5116,6 +5116,8 @@ * If the process owned PMCs, free them up and free up memory. */ if ((po = pmc_find_owner_descriptor(p)) != NULL) { + if ((po->po_flags & PMC_PO_OWNS_LOGFILE) != 0) + pmclog_close(po); pmc_remove_owner(po); pmc_destroy_owner_descriptor(po); }