]> git.proxmox.com Git - ovs.git/commitdiff
netdev: Count ports within mutex.
authorJoe Stringer <joe@ovn.org>
Wed, 16 Nov 2016 00:15:04 +0000 (16:15 -0800)
committerJoe Stringer <joe@ovn.org>
Wed, 16 Nov 2016 19:53:50 +0000 (11:53 -0800)
netdev_get_vports() previously counted the number of ports outside the
mutex, allocated enough memory for that number, then grabbed the mutex
to iterate through them and filled the array with the pointers.

This is logically wrong; in theory the number of ports could change
between allocating the memory and grabbing the mutex. In practice, only
the main thread manages these so there is no chance for a segfault. Fix
it up anyway.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
lib/netdev.c

index ee9b46123fd2659a8b19cab74333c04c57d3821d..860781dede33d11c85c88efe7428ad51f23ab763 100644 (file)
@@ -1766,8 +1766,8 @@ netdev_get_vports(size_t *size)
     }
 
     /* Explicitly allocates big enough chunk of memory. */
-    vports = xmalloc(shash_count(&netdev_shash) * sizeof *vports);
     ovs_mutex_lock(&netdev_mutex);
+    vports = xmalloc(shash_count(&netdev_shash) * sizeof *vports);
     SHASH_FOR_EACH (node, &netdev_shash) {
         struct netdev *dev = node->data;