netdev-linux: Fix pairing of rtnetlink register and unregister calls.
authorBen Pfaff <blp@nicira.com>
Mon, 13 Dec 2010 21:07:48 +0000 (13:07 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 13 Dec 2010 22:29:13 +0000 (14:29 -0800)
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

index ed97eb3..1efbfd8 100644 (file)
@@ -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);