summaryrefslogtreecommitdiffstats
path: root/reftable
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-12-23 18:32:06 +0100
committerJunio C Hamano <gitster@pobox.com>2024-12-23 18:32:06 +0100
commit3151e6a1214b583552ca39c57d429a8eaa8923e8 (patch)
treef3fee4fde1850a6d929445ab02001cc75351d50a /reftable
parentFinishing touches before 2.48-rc1 (diff)
parentreftable/basics: return NULL on zero-sized allocations (diff)
downloadgit-3151e6a1214b583552ca39c57d429a8eaa8923e8.tar.xz
git-3151e6a1214b583552ca39c57d429a8eaa8923e8.zip
Merge branch 'ps/reftable-alloc-failures-zalloc-fix'
Recent reftable updates mistook a NULL return from a request for 0-byte allocation as OOM and died unnecessarily, which has been corrected. * ps/reftable-alloc-failures-zalloc-fix: reftable/basics: return NULL on zero-sized allocations reftable/stack: fix zero-sized allocation when there are no readers reftable/merged: fix zero-sized allocation when there are no readers reftable/stack: don't perform auto-compaction with less than two tables
Diffstat (limited to 'reftable')
-rw-r--r--reftable/basics.c7
-rw-r--r--reftable/merged.c12
-rw-r--r--reftable/stack.c27
3 files changed, 31 insertions, 15 deletions
diff --git a/reftable/basics.c b/reftable/basics.c
index 7d84a5d62d..70b1091d14 100644
--- a/reftable/basics.c
+++ b/reftable/basics.c
@@ -17,6 +17,8 @@ static void (*reftable_free_ptr)(void *);
void *reftable_malloc(size_t sz)
{
+ if (!sz)
+ return NULL;
if (reftable_malloc_ptr)
return (*reftable_malloc_ptr)(sz);
return malloc(sz);
@@ -24,6 +26,11 @@ void *reftable_malloc(size_t sz)
void *reftable_realloc(void *p, size_t sz)
{
+ if (!sz) {
+ reftable_free(p);
+ return NULL;
+ }
+
if (reftable_realloc_ptr)
return (*reftable_realloc_ptr)(p, sz);
return realloc(p, sz);
diff --git a/reftable/merged.c b/reftable/merged.c
index bb0836e344..e72b39e178 100644
--- a/reftable/merged.c
+++ b/reftable/merged.c
@@ -240,14 +240,16 @@ int merged_table_init_iter(struct reftable_merged_table *mt,
struct reftable_iterator *it,
uint8_t typ)
{
- struct merged_subiter *subiters;
+ struct merged_subiter *subiters = NULL;
struct merged_iter *mi = NULL;
int ret;
- REFTABLE_CALLOC_ARRAY(subiters, mt->readers_len);
- if (!subiters) {
- ret = REFTABLE_OUT_OF_MEMORY_ERROR;
- goto out;
+ if (mt->readers_len) {
+ REFTABLE_CALLOC_ARRAY(subiters, mt->readers_len);
+ if (!subiters) {
+ ret = REFTABLE_OUT_OF_MEMORY_ERROR;
+ goto out;
+ }
}
for (size_t i = 0; i < mt->readers_len; i++) {
diff --git a/reftable/stack.c b/reftable/stack.c
index 59fd695a12..634f0c5425 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -270,9 +270,9 @@ static int reftable_stack_reload_once(struct reftable_stack *st,
int reuse_open)
{
size_t cur_len = !st->merged ? 0 : st->merged->readers_len;
- struct reftable_reader **cur;
+ struct reftable_reader **cur = NULL;
struct reftable_reader **reused = NULL;
- struct reftable_reader **new_readers;
+ struct reftable_reader **new_readers = NULL;
size_t reused_len = 0, reused_alloc = 0, names_len;
size_t new_readers_len = 0;
struct reftable_merged_table *new_merged = NULL;
@@ -280,18 +280,22 @@ static int reftable_stack_reload_once(struct reftable_stack *st,
int err = 0;
size_t i;
- cur = stack_copy_readers(st, cur_len);
- if (!cur) {
- err = REFTABLE_OUT_OF_MEMORY_ERROR;
- goto done;
+ if (cur_len) {
+ cur = stack_copy_readers(st, cur_len);
+ if (!cur) {
+ err = REFTABLE_OUT_OF_MEMORY_ERROR;
+ goto done;
+ }
}
names_len = names_length(names);
- new_readers = reftable_calloc(names_len, sizeof(*new_readers));
- if (!new_readers) {
- err = REFTABLE_OUT_OF_MEMORY_ERROR;
- goto done;
+ if (names_len) {
+ new_readers = reftable_calloc(names_len, sizeof(*new_readers));
+ if (!new_readers) {
+ err = REFTABLE_OUT_OF_MEMORY_ERROR;
+ goto done;
+ }
}
while (*names) {
@@ -1627,6 +1631,9 @@ int reftable_stack_auto_compact(struct reftable_stack *st)
struct segment seg;
uint64_t *sizes;
+ if (st->merged->readers_len < 2)
+ return 0;
+
sizes = stack_table_sizes_for_compaction(st);
if (!sizes)
return REFTABLE_OUT_OF_MEMORY_ERROR;