diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-01-01 09:21:13 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-01-01 09:21:13 -0800 |
| commit | 73e35b172a74cfab8f1db450113f2bf826b40b60 (patch) | |
| tree | e11a2f43cfbd98fb8bb589e2be9ccf38eeb19302 /reftable/basics.c | |
| parent | Git 2.48-rc1 (diff) | |
| parent | t-reftable-merged: handle realloc errors (diff) | |
| download | git-73e35b172a74cfab8f1db450113f2bf826b40b60.tar.gz git-73e35b172a74cfab8f1db450113f2bf826b40b60.zip | |
Merge branch 'rs/reftable-realloc-errors'
The custom allocator code in the reftable library did not handle
failing realloc() very well, which has been addressed.
* rs/reftable-realloc-errors:
t-reftable-merged: handle realloc errors
reftable: handle realloc error in parse_names()
reftable: fix allocation count on realloc error
reftable: avoid leaks on realloc error
Diffstat (limited to 'reftable/basics.c')
| -rw-r--r-- | reftable/basics.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/reftable/basics.c b/reftable/basics.c index 70b1091d14..fe2b83ff83 100644 --- a/reftable/basics.c +++ b/reftable/basics.c @@ -124,11 +124,8 @@ int reftable_buf_add(struct reftable_buf *buf, const void *data, size_t len) size_t newlen = buf->len + len; if (newlen + 1 > buf->alloc) { - char *reallocated = buf->buf; - REFTABLE_ALLOC_GROW(reallocated, newlen + 1, buf->alloc); - if (!reallocated) + if (REFTABLE_ALLOC_GROW(buf->buf, newlen + 1, buf->alloc)) return REFTABLE_OUT_OF_MEMORY_ERROR; - buf->buf = reallocated; } memcpy(buf->buf + buf->len, data, len); @@ -233,11 +230,9 @@ char **parse_names(char *buf, int size) next = end; } if (p < next) { - char **names_grown = names; - REFTABLE_ALLOC_GROW(names_grown, names_len + 1, names_cap); - if (!names_grown) + if (REFTABLE_ALLOC_GROW(names, names_len + 1, + names_cap)) goto err; - names = names_grown; names[names_len] = reftable_strdup(p); if (!names[names_len++]) @@ -246,7 +241,8 @@ char **parse_names(char *buf, int size) p = next + 1; } - REFTABLE_REALLOC_ARRAY(names, names_len + 1); + if (REFTABLE_ALLOC_GROW(names, names_len + 1, names_cap)) + goto err; names[names_len] = NULL; return names; |
