Hi, this is the third version of this patch series that converts the reftable library to start handling allocation errors. This is done such that the reftable library can truly behave like a library and let its callers handle such conditions. There is only a single change compared to v1, namely that we use `reftable_free()` instead of `free()`. Thanks! Patrick Patrick Steinhardt (22): reftable/error: introduce out-of-memory error code reftable/basics: merge "publicbasics" into "basics" reftable: introduce `reftable_strdup()` reftable/basics: handle allocation failures in `reftable_calloc()` reftable/basics: handle allocation failures in `parse_names()` reftable/record: handle allocation failures on copy reftable/record: handle allocation failures when decoding records reftable/writer: handle allocation failures in `writer_index_hash()` reftable/writer: handle allocation failures in `reftable_new_writer()` reftable/merged: handle allocation failures in `merged_table_init_iter()` reftable/reader: handle allocation failures for unindexed reader reftable/reader: handle allocation failures in `reader_init_iter()` reftable/stack: handle allocation failures on reload reftable/stack: handle allocation failures in `reftable_new_stack()` reftable/stack: handle allocation failures in `stack_compact_range()` reftable/stack: handle allocation failures in auto compaction reftable/iter: handle allocation failures when creating indexed table iter reftable/blocksource: handle allocation failures reftable/block: handle allocation failures reftable/pq: handle allocation failures when adding entries reftable/tree: handle allocation failures reftable: handle trivial allocation failures Makefile | 1 - refs/reftable-backend.c | 39 ++++-- reftable/basics.c | 92 ++++++++++++++- reftable/basics.h | 13 +- reftable/block.c | 23 +++- reftable/block.h | 4 +- reftable/blocksource.c | 25 +++- reftable/error.c | 2 + reftable/iter.c | 20 +++- reftable/iter.h | 2 +- reftable/merged.c | 84 ++++++++----- reftable/merged.h | 6 +- reftable/pq.c | 7 +- reftable/pq.h | 2 +- reftable/publicbasics.c | 66 ----------- reftable/reader.c | 68 ++++++++--- reftable/reader.h | 6 +- reftable/record.c | 164 +++++++++++++++++++------- reftable/record.h | 6 +- reftable/reftable-basics.h | 18 +++ reftable/reftable-error.h | 3 + reftable/reftable-malloc.h | 18 --- reftable/reftable-merged.h | 8 +- reftable/reftable-reader.h | 8 +- reftable/reftable-stack.h | 8 +- reftable/reftable-writer.h | 12 +- reftable/stack.c | 177 ++++++++++++++++++++++------ reftable/tree.c | 42 +++++-- reftable/tree.h | 21 +++- reftable/writer.c | 150 +++++++++++++++-------- t/helper/test-reftable.c | 10 +- t/unit-tests/lib-reftable.c | 8 +- t/unit-tests/t-reftable-basics.c | 11 +- t/unit-tests/t-reftable-block.c | 24 ++-- t/unit-tests/t-reftable-merged.c | 16 ++- t/unit-tests/t-reftable-readwrite.c | 61 ++++++---- t/unit-tests/t-reftable-stack.c | 4 +- t/unit-tests/t-reftable-tree.c | 10 +- 38 files changed, 853 insertions(+), 386 deletions(-) delete mode 100644 reftable/publicbasics.c create mode 100644 reftable/reftable-basics.h delete mode 100644 reftable/reftable-malloc.h Range-diff against v2: 1: 8c99ecc325 = 1: 8c99ecc325 reftable/error: introduce out-of-memory error code 2: 4dcdf1d48e = 2: 4dcdf1d48e reftable/basics: merge "publicbasics" into "basics" 3: 21fa9b15d9 = 3: 21fa9b15d9 reftable: introduce `reftable_strdup()` 4: f6ad92ffd0 = 4: f6ad92ffd0 reftable/basics: handle allocation failures in `reftable_calloc()` 5: ad028020df ! 5: 922783708d reftable/basics: handle allocation failures in `parse_names()` @@ reftable/basics.c: void parse_names(char *buf, int size, char ***namesp) + +err: + for (size_t i = 0; i < names_len; i++) -+ free(names[i]); -+ free(names); ++ reftable_free(names[i]); ++ reftable_free(names); + return NULL; } 6: df713fbe08 = 6: d4676e8a6a reftable/record: handle allocation failures on copy 7: 870bb003c0 = 7: 874e6a1c20 reftable/record: handle allocation failures when decoding records 8: 1d47e42500 = 8: 42bc57fd00 reftable/writer: handle allocation failures in `writer_index_hash()` 9: caa71f0a77 = 9: 9edd1d84cd reftable/writer: handle allocation failures in `reftable_new_writer()` 10: a84e9cadae = 10: d4004a7f43 reftable/merged: handle allocation failures in `merged_table_init_iter()` 11: 20d3833014 = 11: b2bd142021 reftable/reader: handle allocation failures for unindexed reader 12: e35c3a705d = 12: 9b5fd52862 reftable/reader: handle allocation failures in `reader_init_iter()` 13: ca3b57f151 = 13: 0f3e3d1585 reftable/stack: handle allocation failures on reload 14: 7377421a63 = 14: c88645a251 reftable/stack: handle allocation failures in `reftable_new_stack()` 15: 244e8667c5 = 15: 92ad4fc934 reftable/stack: handle allocation failures in `stack_compact_range()` 16: 99f4868c38 = 16: 19acebd919 reftable/stack: handle allocation failures in auto compaction 17: 271839a626 = 17: 620658bffc reftable/iter: handle allocation failures when creating indexed table iter 18: c41808e9d7 = 18: 48047dd4c9 reftable/blocksource: handle allocation failures 19: 9348b0a457 = 19: 08685605ba reftable/block: handle allocation failures 20: 445daf9464 = 20: a66937b7af reftable/pq: handle allocation failures when adding entries 21: c31f9e53f5 = 21: c291114553 reftable/tree: handle allocation failures 22: d0fe999371 = 22: 20f50c446a reftable: handle trivial allocation failures -- 2.46.2.852.g229c0bf0e5.dirty