]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: fix fd leak inside handle_netns
authorJohn Crispin <john@phrozen.org>
Fri, 17 May 2019 19:29:53 +0000 (21:29 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 24 May 2019 08:44:25 +0000 (10:44 +0200)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
phy.c

diff --git a/phy.c b/phy.c
index a4425ea7b1fa64dc43a8eb95663bfd21fe9534c7..ba89d46b3f2f776990dbf1f2a63583730ce4b75f 100644 (file)
--- a/phy.c
+++ b/phy.c
@@ -1,6 +1,7 @@
 #include <stdbool.h>
 #include <errno.h>
 #include <strings.h>
+#include <unistd.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -531,7 +532,7 @@ static int handle_netns(struct nl80211_state *state,
                        enum id_input id)
 {
        char *end;
-       int fd;
+       int fd = -1;
 
        if (argc < 1 || !*argv[0])
                return 1;
@@ -559,6 +560,8 @@ static int handle_netns(struct nl80211_state *state,
        return 1;
 
  nla_put_failure:
+       if (fd >= 0)
+               close(fd);
        return -ENOBUFS;
 }
 COMMAND(set, netns, "{ <pid> | name <nsname> }",