diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-10-02 12:56:31 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-10-02 07:53:55 -0700 |
| commit | 12b90780667ac1e1235ec4106d94c558a28880f7 (patch) | |
| tree | 0a13fb6edafdbb71bae0a32189f42d70b99531d8 /reftable/writer.c | |
| parent | 51afc709dc2f502442220954fb3e32f53eeb1e4e (diff) | |
| download | git-12b90780667ac1e1235ec4106d94c558a28880f7.tar.gz | |
reftable: handle trivial allocation failures
Handle trivial allocation failures in the reftable library and its unit
tests.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/writer.c')
| -rw-r--r-- | reftable/writer.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/reftable/writer.c b/reftable/writer.c index e180c10840..550172e65c 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -49,8 +49,14 @@ static int padded_write(struct reftable_writer *w, uint8_t *data, size_t len, { int n = 0; if (w->pending_padding > 0) { - uint8_t *zeroed = reftable_calloc(w->pending_padding, sizeof(*zeroed)); - int n = w->write(w->write_arg, zeroed, w->pending_padding); + uint8_t *zeroed; + int n; + + zeroed = reftable_calloc(w->pending_padding, sizeof(*zeroed)); + if (!zeroed) + return -1; + + n = w->write(w->write_arg, zeroed, w->pending_padding); if (n < 0) return n; @@ -767,6 +773,9 @@ static int writer_flush_nonempty_block(struct reftable_writer *w) * case we will end up with a multi-level index. */ REFTABLE_ALLOC_GROW(w->index, w->index_len + 1, w->index_cap); + if (!w->index) + return REFTABLE_OUT_OF_MEMORY_ERROR; + index_record.offset = w->next; strbuf_reset(&index_record.last_key); strbuf_addbuf(&index_record.last_key, &w->block_writer->last_key); |
