From e740353f0aa82f438a9c88e4f39a85763e2d9c6a Mon Sep 17 00:00:00 2001 From: Greg Kaiser Date: Mon, 4 Mar 2019 14:00:34 -0800 Subject: [PATCH] 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 --- cmds/ip-up-vpn/ip-up-vpn.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmds/ip-up-vpn/ip-up-vpn.c b/cmds/ip-up-vpn/ip-up-vpn.c index 3b8955b166..71f08375f7 100644 --- a/cmds/ip-up-vpn/ip-up-vpn.c +++ b/cmds/ip-up-vpn/ip-up-vpn.c @@ -95,6 +95,7 @@ int main(int argc, char **argv) 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 @@ int main(int argc, char **argv) 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 @@ int main(int argc, char **argv) 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 @@ int main(int argc, char **argv) fprintf(state, "%s\n", env("REMOTE_ADDR")); } else { ALOGE("Cannot parse parameters"); + fclose(state); return 1; }