-/*
- * Extend the allocated size of the metadata cache. Called only from
- * lttng_ustconsumer_write_metadata_cache.
- *
- * Return 0 on success, a negative value on error.
- */
-static int extend_metadata_cache(struct consumer_metadata_cache *cache,
- unsigned int size)
-{
- int ret = 0;
- char *tmp_data_ptr;
- unsigned int new_size, old_size;
-
- assert(cache);
-
- old_size = cache->cache_alloc_size;
- new_size = max_t(unsigned int, old_size + size, old_size << 1);
- DBG("Extending metadata cache: old size = %u, new size = %u", old_size,
- new_size);
-
- tmp_data_ptr = realloc(cache->data, new_size);
- if (!tmp_data_ptr) {
- ERR("Failed to re-allocate metadata cache");
- free(cache->data);
- ret = -1;
- goto end;
- }
-
- /* Zero newly allocated memory. */
- memset(tmp_data_ptr + old_size, 0, new_size - old_size);
- cache->data = tmp_data_ptr;
- cache->cache_alloc_size = new_size;
-
-end:
- return ret;
-}
-