diff mbox series

[ovs-dev,PATCHv2] netdev: Fix memory leak on error path.

Message ID 1507832565-3149-1-git-send-email-u9012063@gmail.com
State Accepted
Headers show
Series [ovs-dev,PATCHv2] netdev: Fix memory leak on error path. | expand

Commit Message

William Tu Oct. 12, 2017, 6:22 p.m. UTC
Instead of freeing in the error path, move the allocation
after it.  Found by inspection.

Signed-off-by: William Tu <u9012063@gmail.com>
---
 lib/netdev.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Ben Pfaff Oct. 12, 2017, 10:18 p.m. UTC | #1
On Thu, Oct 12, 2017 at 11:22:45AM -0700, William Tu wrote:
> Instead of freeing in the error path, move the allocation
> after it.  Found by inspection.
> 
> Signed-off-by: William Tu <u9012063@gmail.com>

Thanks, applied to master and backported to 2.8.
diff mbox series

Patch

diff --git a/lib/netdev.c b/lib/netdev.c
index b4e570bafd08..e47bfe1c831d 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -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;