all repos — cgit @ 76dc7a3371e487fdc9de7b3b4c991fe370598f0e

a hyperfast web frontend for git written in c

cache: fix resource leak: close file handle before return

Coverity-id: 13910
Signed-off-by: Christian Hesse <mail@eworm.de>
Christian Hesse mail@eworm.de
Sat, 10 Oct 2015 16:56:28 +0200
commit

76dc7a3371e487fdc9de7b3b4c991fe370598f0e

parent

ed5dccbeaab5c8b30e1c2fe8890fa098537a2621

1 files changed, 9 insertions(+), 3 deletions(-)

jump to
M cache.ccache.c

@@ -215,19 +215,25 @@ if (tmp == -1)

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))