about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Hesse <mail@eworm.de>2015-10-10 16:56:28 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2015-10-10 21:41:04 +0200
commit76dc7a3371e487fdc9de7b3b4c991fe370598f0e (patch)
treed64fec2f225fec6c89f8a4cbe48b23e04750ef04
parentui-atom: fix resource leak: free allocation from cgit_pageurl (diff)
downloadcgit-pink-76dc7a3371e487fdc9de7b3b4c991fe370598f0e.tar.gz
cgit-pink-76dc7a3371e487fdc9de7b3b4c991fe370598f0e.zip
cache: fix resource leak: close file handle before return
Coverity-id: 13910
Signed-off-by: Christian Hesse <mail@eworm.de>
Diffstat (limited to '')
-rw-r--r--cache.c12
1 files 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))
w this syntax worked! 2017-07-30Add juneJune McEnroe 2017-07-30Play nethack as ValkyrieJune McEnroe 2017-07-28Add toggle to hnelJune McEnroe 2017-07-28Install slJune McEnroe 2017-07-25Add up, supJune McEnroe 2017-07-24Autopickup ringsJune McEnroe 2017-07-24Name dogJune McEnroe 2017-07-23Add nethackrcJune McEnroe 2017-07-23Remove useless setuid in briJune McEnroe Don't you think it would be better if the setuid bit only gave you permission to do it and didn't do it for you? 2017-07-23Clean up hnel a tiny bitJune McEnroe 2017-07-21Set window size in hnelJune McEnroe 2017-07-21Add hnelJune McEnroe 2017-07-19chmod 600 in dtchJune McEnroe