]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
monitor: fix file handle leak
authorStephen Hemminger <stephen@networkplumber.org>
Thu, 31 Dec 2015 01:19:04 +0000 (17:19 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 31 Dec 2015 01:26:38 +0000 (17:26 -0800)
In some cases passing file to monitor left file open.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/ipmonitor.c
ip/xfrm_monitor.c
tc/tc_monitor.c

index 8bcf8822b398d4c239694ab748553511a2beaf40..99a237f479241406219ae76a424ab6b50119918a 100644 (file)
@@ -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)
index 8b21efad55f4f7fc1d8177dd9f2a6f4a8b851e34..e6e991afc5daadd2ef8f0ef77b54ae56c22a0aa9 100644 (file)
@@ -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)
index 097068e91e51f865a3f9a5baa0c0c381a1e74198..ebb94320837bd123f721d134c6892a194169ae32 100644 (file)
@@ -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)