From: Stephen Hemminger Date: Thu, 31 Dec 2015 01:19:04 +0000 (-0800) Subject: monitor: fix file handle leak X-Git-Tag: v4.5.0~93^2~9^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e49b51d6631290bf2df0efd56aa511e3387216ea;p=thirdparty%2Fiproute2.git monitor: fix file handle leak In some cases passing file to monitor left file open. Signed-off-by: Stephen Hemminger --- diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c index 8bcf8822b..99a237f47 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 8b21efad5..e6e991afc 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 097068e91..ebb943208 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)