cache: fix resource leak: close file handle before return

Coverity-id: 13910
Signed-off-by: Christian Hesse <mail@eworm.de>
这个提交包含在:
Christian Hesse 2015-10-10 16:56:28 +02:00 提交者 Jason A. Donenfeld
父节点 ed5dccbeaa
当前提交 76dc7a3371

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