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>
}
/* 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;