]> git.itanic.dy.fi Git - rrdd/commitdiff
rrdtool: get_last_update: Fix file descriptor leak
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sun, 25 Oct 2020 16:17:08 +0000 (18:17 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sun, 25 Oct 2020 16:17:08 +0000 (18:17 +0200)
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 <timo.t.kokkonen@iki.fi>
rrdtool.c

index ece5d12d7d5485954ab779b326d874fc2a79c6d4..df189505f541a624379cf8671c6bd0a86ebef3da 100644 (file)
--- 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;