]> git.ipfire.org Git - thirdparty/git.git/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 0044eecd9aa39afa476dcfb8e6eeaaa89fb08b86..2605371c28d86f638dcd5079466e038e3eb7a38a 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;