about summary refs log tree commit diff stats
path: root/cache.c
diff options
context:
space:
mode:
authorChristian Hesse2015-10-10 16:56:28 +0200
committerJason A. Donenfeld2015-10-10 21:41:04 +0200
commit76dc7a3371e487fdc9de7b3b4c991fe370598f0e (patch)
treed64fec2f225fec6c89f8a4cbe48b23e04750ef04 /cache.c
parentui-atom: fix resource leak: free allocation from cgit_pageurl (diff)
downloadcgit-76dc7a3371e487fdc9de7b3b4c991fe370598f0e.tar.gz
cgit-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 'cache.c')
-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)
215 return errno; 215 return errno;
216 216
217 /* Redirect stdout to lockfile */ 217 /* Redirect stdout to lockfile */
218 if (dup2(slot->lock_fd, STDOUT_FILENO) == -1) 218 if (dup2(slot->lock_fd, STDOUT_FILENO) == -1) {
219 close(tmp);
219 return errno; 220 return errno;
221 }
220 222
221 /* Generate cache content */ 223 /* Generate cache content */
222 slot->fn(); 224 slot->fn();
223 225
224 /* update stat info */ 226 /* update stat info */
225 if (fstat(slot->lock_fd, &slot->cache_st)) 227 if (fstat(slot->lock_fd, &slot->cache_st)) {
228 close(tmp);
226 return errno; 229 return errno;
230 }
227 231
228 /* Restore stdout */ 232 /* Restore stdout */
229 if (dup2(tmp, STDOUT_FILENO) == -1) 233 if (dup2(tmp, STDOUT_FILENO) == -1) {
234 close(tmp);
230 return errno; 235 return errno;
236 }
231 237
232 /* Close the temporary filedescriptor */ 238 /* Close the temporary filedescriptor */
233 if (close(tmp)) 239 if (close(tmp))