Skip to contentSkip to conversation

Fix file descriptor leak in do_tunnels_list()

PATCH In review Thomas Jarosch 1 participant 1 message Oct 3, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 10/11 Fix file descriptor leak in do_tunnels_list()

Detected by cppcheck.

---
 ip/iptunnel.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
ip/iptunnel.c +3 -0
index f038f0a..3d41a27 100644
@@ -411,6 +411,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
 	if (!fgets(buf, sizeof(buf), fp) ||
 	    !fgets(buf, sizeof(buf), fp)) {
 		fprintf(stderr, "/proc/net/dev read error\n");
+		fclose(fp);
 		return -1;
 	}
 
@@ -421,6 +422,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
 		if ((ptr = strchr(buf, ':')) == NULL ||
 		    (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
 			fprintf(stderr, "Wrong format of /proc/net/dev. Sorry.\n");
+			fclose(fp);
 			return -1;
 		}
 		if (sscanf(ptr, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld",
@@ -462,6 +464,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
 		}
 		printf("\n");
 	}
+	fclose(fp);
 	return 0;
 }
 
Signature · 1 line
1.7.4.4