]> git.proxmox.com Git - ovs.git/commitdiff
netdev: Fix memory leak on error path.
authorWilliam Tu <u9012063@gmail.com>
Thu, 12 Oct 2017 18:22:45 +0000 (11:22 -0700)
committerBen Pfaff <blp@ovn.org>
Thu, 12 Oct 2017 21:50:03 +0000 (14:50 -0700)
Instead of freeing in the error path, move the allocation
after it.  Found by inspection.

Signed-off-by: William Tu <u9012063@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
lib/netdev.c

index b4e570bafd08533d22d4f61f1af8bbeadff4bea1..e47bfe1c831d4e619c85bda619da594b92d70697 100644 (file)
@@ -2214,19 +2214,18 @@ netdev_ports_insert(struct netdev *netdev, const struct dpif_class *dpif_class,
         return ENODEV;
     }
 
-    data = xzalloc(sizeof *data);
-    ifidx = xzalloc(sizeof *ifidx);
-
     ovs_mutex_lock(&netdev_hmap_mutex);
     if (netdev_ports_lookup(dpif_port->port_no, dpif_class)) {
         ovs_mutex_unlock(&netdev_hmap_mutex);
         return EEXIST;
     }
 
+    data = xzalloc(sizeof *data);
     data->netdev = netdev_ref(netdev);
     data->dpif_class = dpif_class;
     dpif_port_clone(&data->dpif_port, dpif_port);
 
+    ifidx = xzalloc(sizeof *ifidx);
     ifidx->ifindex = ifindex;
     ifidx->port = dpif_port->port_no;