avoid double-free

This commit is contained in:
mlelstv 2021-06-15 04:39:49 +00:00
parent 76313cf46e
commit 2bcef4d56c
4 changed files with 14 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: am2315.c,v 1.5 2018/06/17 01:08:15 thorpej Exp $ */
/* $NetBSD: am2315.c,v 1.6 2021/06/15 04:40:13 mlelstv Exp $ */
/*
* Copyright (c) 2017 Brad Spencer <brad@anduin.eldar.org>
@ -17,7 +17,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.5 2018/06/17 01:08:15 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: am2315.c,v 1.6 2021/06/15 04:40:13 mlelstv Exp $");
/*
* Driver for the Aosong AM2315
@ -458,10 +458,8 @@ am2315_detach(device_t self, int flags)
mutex_enter(&sc->sc_mutex);
/* Remove the sensors */
if (sc->sc_sme != NULL) {
if (sc->sc_sme != NULL)
sysmon_envsys_unregister(sc->sc_sme);
sc->sc_sme = NULL;
}
mutex_exit(&sc->sc_mutex);
/* Destroy the wait cond */

View File

@ -1,4 +1,4 @@
/* $NetBSD: dbcool.c,v 1.60 2021/01/30 01:22:06 thorpej Exp $ */
/* $NetBSD: dbcool.c,v 1.61 2021/06/15 04:39:49 mlelstv Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -50,7 +50,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.60 2021/01/30 01:22:06 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.61 2021/06/15 04:39:49 mlelstv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -819,11 +819,11 @@ dbcool_detach(device_t self, int flags)
pmf_device_deregister(self);
sysmon_envsys_unregister(sc->sc_sme);
if (sc->sc_sme != NULL)
sysmon_envsys_unregister(sc->sc_sme);
sysctl_teardown(&sc->sc_sysctl_log);
sc->sc_sme = NULL;
return 0;
}
@ -1600,6 +1600,7 @@ dbcool_setup(device_t self)
out:
sysmon_envsys_destroy(sc->sc_sme);
sc->sc_sme = NULL;
}
static int

View File

@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.13 2021/01/27 02:29:48 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.14 2021/06/15 04:39:49 mlelstv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -204,6 +204,7 @@ hytp14_attach(device_t parent, device_t self, void *aux)
aprint_error_dev(sc->sc_dev,
"unable to register with sysmon\n");
sysmon_envsys_destroy(sc->sc_sme);
sc->sc_sme = NULL;
return;
}
@ -244,10 +245,8 @@ hytp14_detach(device_t self, int flags)
sc = device_private(self);
if (sc->sc_sme != NULL) {
if (sc->sc_sme != NULL)
sysmon_envsys_unregister(sc->sc_sme);
sc->sc_sme = NULL;
}
/* stop measurement thread */
mutex_enter(&sc->sc_mutex);

View File

@ -1,4 +1,4 @@
/* $NetBSD: si70xx.c,v 1.6 2020/12/05 14:50:33 jdc Exp $ */
/* $NetBSD: si70xx.c,v 1.7 2021/06/15 04:39:49 mlelstv Exp $ */
/*
* Copyright (c) 2017 Brad Spencer <brad@anduin.eldar.org>
@ -17,7 +17,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.6 2020/12/05 14:50:33 jdc Exp $");
__KERNEL_RCSID(0, "$NetBSD: si70xx.c,v 1.7 2021/06/15 04:39:49 mlelstv Exp $");
/*
Driver for the Silicon Labs SI7013/SI7020/SI7021
@ -968,10 +968,8 @@ si70xx_detach(device_t self, int flags)
mutex_enter(&sc->sc_mutex);
/* Remove the sensors */
if (sc->sc_sme != NULL) {
if (sc->sc_sme != NULL)
sysmon_envsys_unregister(sc->sc_sme);
sc->sc_sme = NULL;
}
mutex_exit(&sc->sc_mutex);
/* Remove the sysctl tree */