diff mbox

[NETMAP,1/2] linux-netmap: fix device control sockfd leakage

Message ID 1429525035-21377-2-git-send-email-ciprian.barbu@linaro.org
State New
Headers show

Commit Message

Ciprian Barbu April 20, 2015, 10:17 a.m. UTC
The get_mac_addr function created a socket that was never freed. The device
control socket should have been used instead

Signed-off-by: Ciprian Barbu <ciprian.barbu@linaro.org>
---
 platform/linux-netmap/odp_packet_netmap.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-netmap/odp_packet_netmap.c b/platform/linux-netmap/odp_packet_netmap.c
index a4236cf..2988b96 100644
--- a/platform/linux-netmap/odp_packet_netmap.c
+++ b/platform/linux-netmap/odp_packet_netmap.c
@@ -87,8 +87,13 @@  struct dispatch_args {
 
 int odp_netmap_init_global(void)
 {
+	int i;
 	odp_spinlock_init(&nm_global_lock);
 	memset(netmap_devs, 0, sizeof(netmap_devs));
+
+	for (i = 0; i < MAX_DEVS; i++)
+		netmap_devs[i].sockfd = -1;
+
 	return 0;
 }
 
@@ -148,9 +153,9 @@  static int get_mac_addr(pkt_netmap_t *pkt_nm)
 	int sockfd;
 	int err;
 
-	sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+	sockfd = pkt_nm->nm_dev->sockfd;
 	if (sockfd == -1) {
-		ODP_ERR("socket(): %s\n", strerror(errno));
+		ODP_ERR("Error: invalid device control socket\n");
 		goto error;
 	}