summaryrefslogtreecommitdiff
path: root/reftable/reader.c
diff options
context:
space:
mode:
authorLibravatar Han-Wen Nienhuys <hanwen@google.com>2022-01-20 15:12:01 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2022-01-20 11:31:52 -0800
commit24d4d38c0b32fd4eb075af89d7b744c5647db5c2 (patch)
treecc34419ff31ed2e2ded0670ae2df522cf5fa18c8 /reftable/reader.c
parentreftable: fix OOB stack write in print functions (diff)
downloadtgif-24d4d38c0b32fd4eb075af89d7b744c5647db5c2.tar.xz
reftable: fix resource leak in block.c error path
Add test coverage for corrupt zlib data. Fix memory leaks demonstrated by unittest. This problem was discovered by a Coverity scan. Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/reader.c')
-rw-r--r--reftable/reader.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/reftable/reader.c b/reftable/reader.c
index 006709a645..35781593a2 100644
--- a/reftable/reader.c
+++ b/reftable/reader.c
@@ -290,28 +290,33 @@ int reader_init_block_reader(struct reftable_reader *r, struct block_reader *br,
err = reader_get_block(r, &block, next_off, guess_block_size);
if (err < 0)
- return err;
+ goto done;
block_size = extract_block_size(block.data, &block_typ, next_off,
r->version);
- if (block_size < 0)
- return block_size;
-
+ if (block_size < 0) {
+ err = block_size;
+ goto done;
+ }
if (want_typ != BLOCK_TYPE_ANY && block_typ != want_typ) {
- reftable_block_done(&block);
- return 1;
+ err = 1;
+ goto done;
}
if (block_size > guess_block_size) {
reftable_block_done(&block);
err = reader_get_block(r, &block, next_off, block_size);
if (err < 0) {
- return err;
+ goto done;
}
}
- return block_reader_init(br, &block, header_off, r->block_size,
- hash_size(r->hash_id));
+ err = block_reader_init(br, &block, header_off, r->block_size,
+ hash_size(r->hash_id));
+done:
+ reftable_block_done(&block);
+
+ return err;
}
static int table_iter_next_block(struct table_iter *dest,