From a73c04ae00b2eb39c91ae6dddb3981e1a14c967e Mon Sep 17 00:00:00 2001 From: Yifeng Sun Date: Fri, 11 Oct 2019 15:50:47 -0700 Subject: dpif-netlink: Free leaked nl_sock Valgrind reports: 20 bytes in 1 blocks are definitely lost in loss record 94 of 353 by 0x532594: xmalloc (util.c:138) by 0x553EAD: nl_sock_create (netlink-socket.c:146) by 0x54331D: create_nl_sock (dpif-netlink.c:255) by 0x54331D: dpif_netlink_port_add__ (dpif-netlink.c:756) by 0x5435F6: dpif_netlink_port_add_compat (dpif-netlink.c:876) by 0x5435F6: dpif_netlink_port_add (dpif-netlink.c:922) by 0x47EC1D: dpif_port_add (dpif.c:584) by 0x42B35F: port_add (ofproto-dpif.c:3721) by 0x41E64A: ofproto_port_add (ofproto.c:2032) by 0x40B3FE: iface_do_create (bridge.c:1817) by 0x40B3FE: iface_create (bridge.c:1855) by 0x40B3FE: bridge_add_ports__ (bridge.c:943) by 0x40D14A: bridge_add_ports (bridge.c:959) by 0x40D14A: bridge_reconfigure (bridge.c:673) by 0x410D75: bridge_run (bridge.c:3050) by 0x407614: main (ovs-vswitchd.c:127) This leak is because when vport_add_channel() returns 0, it is expected to take the ownership of 'socksp'. This patch fixes this issue. Signed-off-by: Yifeng Sun Signed-off-by: Ben Pfaff --- lib/dpif-netlink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 7bc71d6d1..efdb9acfc 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -457,6 +457,7 @@ vport_add_channel(struct dpif_netlink *dpif, odp_port_t port_no, int error; if (dpif->handlers == NULL) { + close_nl_sock(socksp); return 0; } -- 2.14.1