From b7057b25e3549f6becf0d0a6f9c5b1cb2dca4ccb Mon Sep 17 00:00:00 2001 From: kib Date: Wed, 1 Nov 2017 11:37:45 +0000 Subject: [PATCH] Be protective and check the po_file validity before dropping the ref. Reported and tested by: pho Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week X-Differential revision: https://reviews.freebsd.org/D12882 --- sys/dev/hwpmc/hwpmc_logging.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_logging.c b/sys/dev/hwpmc/hwpmc_logging.c index 7b19bd4ef652..bfd831b69908 100644 --- a/sys/dev/hwpmc/hwpmc_logging.c +++ b/sys/dev/hwpmc/hwpmc_logging.c @@ -681,8 +681,11 @@ pmclog_deconfigure_log(struct pmc_owner *po) } /* drop a reference to the fd */ - error = fdrop(po->po_file, curthread); - po->po_file = NULL; + if (po->po_file != NULL) { + error = fdrop(po->po_file, curthread); + po->po_file = NULL; + } else + error = 0; po->po_error = 0; return (error);