diff mbox series

[4/7] iw: fix fd leak inside handle_netns

Message ID 20190517192956.18372-5-john@phrozen.org (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show
Series iw: various bug fixes | expand

Commit Message

John Crispin May 17, 2019, 7:29 p.m. UTC
Signed-off-by: John Crispin <john@phrozen.org>
---
 phy.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/phy.c b/phy.c
index a4425ea..ba89d46 100644
--- 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> }",