}
}
+static size_t get_required_fdi_capacity(const struct fd_ops *ops_by_buffer[static LOG_ID_MAX])
+{
+ size_t ret = 1; // NULL terminator
+ for (size_t i = 0; i < LOG_ID_MAX; ++i)
+ if (ops_by_buffer[i])
+ ++ ret;
+ return ret;
+}
+
int create_initial_fdis(struct fd_info ***fdis, int enabled_buffers, backend_t backend, bool is_compressed_memory, const struct log_config *conf, log_id_t aliased[LOG_ID_MAX])
{
assert(fdis);
assert(backend != BACKEND_NONE);
assert(backend != BACKEND_NULL);
- __attribute__((cleanup(fdi_array_free))) struct fd_info **fdi_ptrs = NULL;
- int fdi_cnt = 0;
- int r;
-
const struct fd_ops *ops_by_buffer[LOG_ID_MAX];
for (size_t i = 0; i < NELEMS(ops_by_buffer); ++i)
ops_by_buffer[i] = get_ops_by_buffer(i, enabled_buffers, backend, is_compressed_memory);
- fdi_ptrs = calloc(bit_count(enabled_buffers) + 1 /* NULL terminator */, sizeof *fdi_ptrs);
+ int fdi_cnt = 0;
+ __attribute__((cleanup(fdi_array_free))) struct fd_info **fdi_ptrs = calloc(get_required_fdi_capacity(ops_by_buffer), sizeof *fdi_ptrs);
if (!fdi_ptrs)
return TIZEN_ERROR_OUT_OF_MEMORY;
__attribute__ ((cleanup(list_clear_free_contents))) list_head used_paths = NULL;
- fdi_cnt = 0;
for (int i = 0; i < LOG_ID_MAX; ++i) {
const struct fd_ops *const ops = ops_by_buffer[i];
if (!ops)
if (!fdi)
return -ENOMEM;
- r = fdi->ops->create(fdi, conf, i, &used_paths, &aliased[i]);
+ int r = fdi->ops->create(fdi, conf, i, &used_paths, &aliased[i]);
if (r == 0)
aliased[i] = i;
if (r < 0) {