Commit 297452a1 authored by Thomas Jarosch's avatar Thomas Jarosch Committed by Stephen Hemminger

Fix file descriptor leak in do_tunnels_list()

Detected by cppcheck.
Signed-off-by: default avatarThomas Jarosch <thomas.jarosch@intra2net.com>
parent e588a7db
...@@ -411,6 +411,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p) ...@@ -411,6 +411,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
if (!fgets(buf, sizeof(buf), fp) || if (!fgets(buf, sizeof(buf), fp) ||
!fgets(buf, sizeof(buf), fp)) { !fgets(buf, sizeof(buf), fp)) {
fprintf(stderr, "/proc/net/dev read error\n"); fprintf(stderr, "/proc/net/dev read error\n");
fclose(fp);
return -1; return -1;
} }
...@@ -421,6 +422,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p) ...@@ -421,6 +422,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
if ((ptr = strchr(buf, ':')) == NULL || if ((ptr = strchr(buf, ':')) == NULL ||
(*ptr++ = 0, sscanf(buf, "%s", name) != 1)) { (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
fprintf(stderr, "Wrong format of /proc/net/dev. Sorry.\n"); fprintf(stderr, "Wrong format of /proc/net/dev. Sorry.\n");
fclose(fp);
return -1; return -1;
} }
if (sscanf(ptr, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld", 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) ...@@ -462,6 +464,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
} }
printf("\n"); printf("\n");
} }
fclose(fp);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment