[PATCH 03/10] reftable: fix resource leak blocksource.c
- From
Han-Wen Nienhuys via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Dec 7, 2021, 17:45 UTC
- Message-ID
- <97279040dded376c110299cc8f2a6a9f7fc4950a.1638899124.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1152.git.git.1638899124.gitgitgadget@gmail.com>
From: Han-Wen Nienhuys <hanwen@google.com>
This would be triggered in the unlikely event of fstat() failing on an opened file.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> --- reftable/blocksource.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/reftable/blocksource.c b/reftable/blocksource.c index 0044eecd9aa..2605371c28d 100644 --- a/reftable/blocksource.c +++ b/reftable/blocksource.c @@ -134,8 +134,10 @@ int reftable_block_source_from_file(struct reftable_block_source *bs, } err = fstat(fd, &st); - if (err < 0) - return -1; + if (err < 0) { + close(fd); + return REFTABLE_IO_ERROR; + } p = reftable_calloc(sizeof(struct file_block_source)); p->size = st.st_size;
-- gitgitgadget