From adec382c3be9b45bc2d993c60e08583bf7659c80 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sun, 25 Oct 2020 18:17:08 +0200 Subject: [PATCH] rrdtool: get_last_update: Fix file descriptor leak Any file descriptors returned by the run_piped() function must be closed when we no longer need them. Furthermore, we really are not interested about error stream, so don't bother requeseting it at all. Signed-off-by: Timo Kokkonen --- rrdtool.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rrdtool.c b/rrdtool.c index ece5d12..df18950 100644 --- a/rrdtool.c +++ b/rrdtool.c @@ -470,14 +470,14 @@ static int get_last_update(struct rrd_database *db) char *args[10], argstr[ARGSTR_LEN]; char buf[16]; int idx = 0, argcnt = 0; - int ofd, efd, child; + int ofd, child; int ret; add_arg(args, argcnt, argstr, idx, RRDTOOL_CMD); add_arg(args, argcnt, argstr, idx, "last"); add_arg(args, argcnt, argstr, idx, db->filename); - child = run_piped(cmd, args, NULL, &ofd, &efd); + child = run_piped(cmd, args, NULL, &ofd, NULL); ret = read(ofd, buf, sizeof(buf) - 1); if (ret < 0) { pr_err("Error reading: %m\n"); @@ -490,6 +490,7 @@ static int get_last_update(struct rrd_database *db) pr_info("Last update for %s is: %ld, %ld sec ago\n", db->name, db->last_update, time(NULL) - db->last_update); + close(ofd); clear_zombie(child); return 0; -- 2.45.0