vppinfra: fix sock init netns 68/33268/2
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>
Tue, 27 Jul 2021 17:51:27 +0000 (19:51 +0200)
committerFlorin Coras <florin.coras@gmail.com>
Tue, 27 Jul 2021 19:27:09 +0000 (19:27 +0000)
Type: fix

Change-Id: I0ce8183ded601bdab031c9689ca361414fed165f
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
src/vppinfra/socket.c

index 26427d9..2921e00 100644 (file)
@@ -560,7 +560,7 @@ clib_socket_init_netns (clib_socket_t *s, u8 *namespace)
     return clib_socket_init (s);
 
   clib_error_t *error;
-  int old_netns_fd, nfd;
+  int old_netns_fd, nfd = -1;
 
   old_netns_fd = clib_netns_open (NULL /* self */);
   if ((nfd = clib_netns_open (namespace)) == -1)
@@ -580,8 +580,12 @@ clib_socket_init_netns (clib_socket_t *s, u8 *namespace)
 done:
   if (clib_setns (old_netns_fd) == -1)
     clib_warning ("Cannot set old ns");
+
   close (old_netns_fd);
 
+  if (-1 != nfd)
+    close (nfd);
+
   return error;
 }