aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Hemminger <stephen@networkplumber.org>2015-12-30 17:19:04 -0800
committerStephen Hemminger <stephen@networkplumber.org>2015-12-30 17:26:38 -0800
commite49b51d6631290bf2df0efd56aa511e3387216ea (patch)
tree06517a133705ed14e055780a8757926df1ad2a90
parentb27f005b274fb0332dc7e88e2bc1344e11fba143 (diff)
downloadandroid_external_iproute2-e49b51d6631290bf2df0efd56aa511e3387216ea.tar.gz
android_external_iproute2-e49b51d6631290bf2df0efd56aa511e3387216ea.tar.bz2
android_external_iproute2-e49b51d6631290bf2df0efd56aa511e3387216ea.zip
monitor: fix file handle leak
In some cases passing file to monitor left file open. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r--ip/ipmonitor.c6
-rw-r--r--ip/xfrm_monitor.c6
-rw-r--r--tc/tc_monitor.c10
3 files changed, 17 insertions, 5 deletions
diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
index 8bcf882..99a237f 100644
--- a/ip/ipmonitor.c
+++ b/ip/ipmonitor.c
@@ -284,12 +284,16 @@ int do_ipmonitor(int argc, char **argv)
}
if (file) {
FILE *fp;
+ int err;
+
fp = fopen(file, "r");
if (fp == NULL) {
perror("Cannot fopen");
exit(-1);
}
- return rtnl_from_file(fp, accept_msg, stdout);
+ err = rtnl_from_file(fp, accept_msg, stdout);
+ fclose(fp);
+ return err;
}
if (rtnl_open(&rth, groups) < 0)
diff --git a/ip/xfrm_monitor.c b/ip/xfrm_monitor.c
index 8b21efa..e6e991a 100644
--- a/ip/xfrm_monitor.c
+++ b/ip/xfrm_monitor.c
@@ -411,12 +411,16 @@ int do_xfrm_monitor(int argc, char **argv)
if (file) {
FILE *fp;
+ int err;
+
fp = fopen(file, "r");
if (fp == NULL) {
perror("Cannot fopen");
exit(-1);
}
- return rtnl_from_file(fp, xfrm_accept_msg, (void*)stdout);
+ err = rtnl_from_file(fp, xfrm_accept_msg, stdout);
+ fclose(fp);
+ return err;
}
if (rtnl_open_byproto(&rth, groups, NETLINK_XFRM) < 0)
diff --git a/tc/tc_monitor.c b/tc/tc_monitor.c
index 097068e..ebb9432 100644
--- a/tc/tc_monitor.c
+++ b/tc/tc_monitor.c
@@ -91,13 +91,17 @@ int do_tcmonitor(int argc, char **argv)
}
if (file) {
- FILE *fp;
- fp = fopen(file, "r");
+ FILE *fp = fopen(file, "r");
+ int ret;
+
if (fp == NULL) {
perror("Cannot fopen");
exit(-1);
}
- return rtnl_from_file(fp, accept_tcmsg, (void*)stdout);
+
+ ret = rtnl_from_file(fp, accept_tcmsg, stdout);
+ fclose(fp);
+ return ret;
}
if (rtnl_open(&rth, groups) < 0)