]> granicus.if.org Git - cgit/commitdiff
cache: fix resource leak: close file handle before return
authorChristian Hesse <mail@eworm.de>
Sat, 10 Oct 2015 14:56:28 +0000 (16:56 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 10 Oct 2015 19:41:04 +0000 (21:41 +0200)
Coverity-id: 13910
Signed-off-by: Christian Hesse <mail@eworm.de>
cache.c

diff --git a/cache.c b/cache.c
index 57c891864ffb8b70447c6db5fd8366f662aadd39..b169d20f779aaa21ed5c3bd8e4e21c62500a0c90 100644 (file)
--- a/cache.c
+++ b/cache.c
@@ -215,19 +215,25 @@ static int fill_slot(struct cache_slot *slot)
                return errno;
 
        /* Redirect stdout to lockfile */
-       if (dup2(slot->lock_fd, STDOUT_FILENO) == -1)
+       if (dup2(slot->lock_fd, STDOUT_FILENO) == -1) {
+               close(tmp);
                return errno;
+       }
 
        /* Generate cache content */
        slot->fn();
 
        /* update stat info */
-       if (fstat(slot->lock_fd, &slot->cache_st))
+       if (fstat(slot->lock_fd, &slot->cache_st)) {
+               close(tmp);
                return errno;
+       }
 
        /* Restore stdout */
-       if (dup2(tmp, STDOUT_FILENO) == -1)
+       if (dup2(tmp, STDOUT_FILENO) == -1) {
+               close(tmp);
                return errno;
+       }
 
        /* Close the temporary filedescriptor */
        if (close(tmp))