diff --git a/src/libs/compat/freebsd_network/compat.c b/src/libs/compat/freebsd_network/compat.c index ae3adf783c..932227fbde 100644 --- a/src/libs/compat/freebsd_network/compat.c +++ b/src/libs/compat/freebsd_network/compat.c @@ -268,13 +268,19 @@ device_get_softc(device_t dev) void device_set_softc(device_t dev, void *softc) { - if (!(dev->flags & DEVICE_SOFTC_SET)) { + if (dev->softc == softc) + return; + + if ((dev->flags & DEVICE_SOFTC_SET) != 0) { // Not externally allocated. We own it so we must clean it up. free(dev->softc); } dev->softc = softc; - dev->flags |= DEVICE_SOFTC_SET; + if (dev->softc != NULL) + dev->flags |= DEVICE_SOFTC_SET; + else + dev->flags &= ~DEVICE_SOFTC_SET; } @@ -452,7 +458,7 @@ device_delete_child(device_t parent, device_t child) free((char *)parent->description); // Delete softc if we were the ones to allocate it. - if (!(parent->flags & DEVICE_SOFTC_SET)) + if ((parent->flags & DEVICE_SOFTC_SET) != 0) free(parent->softc); free(parent);