Skip to content

Commit 694af03

Browse files
pks-tgitster
authored andcommitted
reftable/stack: handle allocation failures in stack_compact_range()
Handle allocation failures in `stack_compact_range()`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5dbe266 commit 694af03

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

reftable/stack.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,11 @@ static int stack_compact_range(struct reftable_stack *st,
11311131
* from the point of view of the newer process.
11321132
*/
11331133
REFTABLE_CALLOC_ARRAY(table_locks, last - first + 1);
1134+
if (!table_locks) {
1135+
err = REFTABLE_OUT_OF_MEMORY_ERROR;
1136+
goto done;
1137+
}
1138+
11341139
for (i = last + 1; i > first; i--) {
11351140
stack_filename(&table_name, st, reader_name(st->readers[i - 1]));
11361141

@@ -1312,8 +1317,18 @@ static int stack_compact_range(struct reftable_stack *st,
13121317
* thus have to allocate `readers_len + 1` many entries.
13131318
*/
13141319
REFTABLE_CALLOC_ARRAY(names, st->merged->readers_len + 1);
1315-
for (size_t i = 0; i < st->merged->readers_len; i++)
1316-
names[i] = xstrdup(st->readers[i]->name);
1320+
if (!names) {
1321+
err = REFTABLE_OUT_OF_MEMORY_ERROR;
1322+
goto done;
1323+
}
1324+
1325+
for (size_t i = 0; i < st->merged->readers_len; i++) {
1326+
names[i] = reftable_strdup(st->readers[i]->name);
1327+
if (!names[i]) {
1328+
err = REFTABLE_OUT_OF_MEMORY_ERROR;
1329+
goto done;
1330+
}
1331+
}
13171332
first_to_replace = first;
13181333
last_to_replace = last;
13191334
}

0 commit comments

Comments
 (0)