From mboxrd@z Thu Jan 1 00:00:00 1970 From: list at eworm.de (Christian Hesse) Date: Sat, 10 Oct 2015 16:56:28 +0200 Subject: [PATCH 6/6] cache: fix resource leak: close file handle before return In-Reply-To: <1444488988-20082-1-git-send-email-list@eworm.de> References: <1444488988-20082-1-git-send-email-list@eworm.de> Message-ID: <1444488988-20082-6-git-send-email-list@eworm.de> From: Christian Hesse Coverity-id: 13910 Signed-off-by: Christian Hesse --- cache.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cache.c b/cache.c index 57c8918..b169d20 100644 --- 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)) -- 2.6.1