ip-up-vpn: Fix resource leaks in error cases
These leaks aren't really consequential since this is a standalone
command, and these "leaks" are in main(). But by putting in simple
fixes for these, we reduce the noise when using static analysis to
find leaks in Android code.
Test: TreeHugger
Change-Id: I2cbb4585c6c8d59a0eb89a72f17dfc4fbc532249
diff --git a/cmds/ip-up-vpn/ip-up-vpn.c b/cmds/ip-up-vpn/ip-up-vpn.c
index 3b8955b..71f0837 100644
--- a/cmds/ip-up-vpn/ip-up-vpn.c
+++ b/cmds/ip-up-vpn/ip-up-vpn.c
@@ -95,6 +95,7 @@
strncpy(ifr.ifr_name, interface, IFNAMSIZ);
if (ioctl(s, SIOCSIFFLAGS, &ifr)) {
ALOGE("Cannot bring up %s: %s", interface, strerror(errno));
+ fclose(state);
return 1;
}
@@ -102,6 +103,7 @@
if (!set_address(&ifr.ifr_addr, address) ||
ioctl(s, SIOCSIFADDR, &ifr)) {
ALOGE("Cannot set address: %s", strerror(errno));
+ fclose(state);
return 1;
}
@@ -109,6 +111,7 @@
if (set_address(&ifr.ifr_netmask, env("INTERNAL_NETMASK4"))) {
if (ioctl(s, SIOCSIFNETMASK, &ifr)) {
ALOGE("Cannot set netmask: %s", strerror(errno));
+ fclose(state);
return 1;
}
}
@@ -123,6 +126,7 @@
fprintf(state, "%s\n", env("REMOTE_ADDR"));
} else {
ALOGE("Cannot parse parameters");
+ fclose(state);
return 1;
}