From d2bb2799e1b7cf2177140cf4ca8a60312c87625a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 13 Dec 2010 13:07:48 -0800 Subject: [PATCH] netdev-linux: Fix pairing of rtnetlink register and unregister calls. netdev_linux_create() called rtnetlink_notifier_register() for both system and internal devices, but netdev_linux_destroy() only did the reverse accounting for system devices. This fixes the pairing. This isn't really much of a bug, since it would only cause the notifier to be active unnecessarily (not to be removed even though it was needed). At most it was a missed opportunity for optimization, but I don't think that optimization would ever happen anyway. Found with valgrind --leak-check=full --show-reachable=yes. --- lib/netdev-linux.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index ed97eb3c..1efbfd88 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -598,20 +598,22 @@ static void netdev_linux_destroy(struct netdev_dev *netdev_dev_) { struct netdev_dev_linux *netdev_dev = netdev_dev_linux_cast(netdev_dev_); - const char *type = netdev_dev_get_type(netdev_dev_); + const struct netdev_class *class = netdev_dev_get_class(netdev_dev_); if (netdev_dev->tc && netdev_dev->tc->ops->tc_destroy) { netdev_dev->tc->ops->tc_destroy(netdev_dev->tc); } - if (!strcmp(type, "system")) { + if (class == &netdev_linux_class || class == &netdev_internal_class) { cache_notifier_refcount--; if (!cache_notifier_refcount) { rtnetlink_notifier_unregister(&netdev_linux_cache_notifier); } - } else if (!strcmp(type, "tap")) { + } else if (class == &netdev_tap_class) { destroy_tap(netdev_dev); + } else { + NOT_REACHED(); } free(netdev_dev); -- 2.30.2