Skip to content

Commit

Permalink
netdev: Fix memory leak on error path.
Browse files Browse the repository at this point in the history
Instead of freeing in the error path, move the allocation
after it.  Found by inspection.

Signed-off-by: William Tu <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
williamtu authored and blp committed Oct 12, 2017
1 parent 52f7b2c commit d2a5f17
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit d2a5f17

Please sign in to comment.