]> Kevux Git Server - rit/commitdiff
reftable: fix resource leak blocksource.c
authorHan-Wen Nienhuys <hanwen@google.com>
Thu, 20 Jan 2022 15:12:02 +0000 (15:12 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Jan 2022 19:31:52 +0000 (11:31 -0800)
This would be triggered in the unlikely event of fstat() failing on an
opened file.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/blocksource.c

index 0044eec..2605371 100644 (file)
@@ -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;