reftable: fix resource leak blocksource.c
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>
Han-Wen Nienhuys committed
Jan 20, 2022 at 15:12 UTC
27e27ee2249f617b529ac5c9c419d3961885994b
1 file changed
+4
-2
reftable/blocksource.c
+4
-2
@@ -134,8 +134,10 @@ int reftable_block_source_from_file(struct reftable_block_source *bs,
134
}
135
136
err = fstat(fd, &st);
137
- if (err < 0)
138
- return -1;
137
+ if (err < 0) {
138
+ close(fd);
139
+ return REFTABLE_IO_ERROR;
140
+ }
141
142
p = reftable_calloc(sizeof(struct file_block_source));
143
p->size = st.st_size;