Fix: miscellaneous memory handling fixes
[lttng-tools.git] / src / common / consumer-metadata-cache.c
index d8f5001f8b5efed8d12239a4856d46bde3939709..0f086fe9643218ba91837446b031154c91453e58 100644 (file)
@@ -46,14 +46,13 @@ static int extend_metadata_cache(struct lttng_consumer_channel *channel,
 {
        int ret = 0;
        char *tmp_data_ptr;
-       unsigned int new_size;
+       unsigned int new_size, old_size;
 
        assert(channel);
        assert(channel->metadata_cache);
 
-       new_size = max_t(unsigned int,
-                       channel->metadata_cache->cache_alloc_size + size,
-                       channel->metadata_cache->cache_alloc_size << 1);
+       old_size = channel->metadata_cache->cache_alloc_size;
+       new_size = max_t(unsigned int, old_size + size, old_size << 1);
        DBG("Extending metadata cache to %u", new_size);
        tmp_data_ptr = realloc(channel->metadata_cache->data, new_size);
        if (!tmp_data_ptr) {
@@ -62,6 +61,8 @@ static int extend_metadata_cache(struct lttng_consumer_channel *channel,
                ret = -1;
                goto end;
        }
+       /* Zero newly allocated memory */
+       memset(tmp_data_ptr + old_size, 0, new_size - old_size);
        channel->metadata_cache->data = tmp_data_ptr;
        channel->metadata_cache->cache_alloc_size = new_size;
 
This page took 0.023138 seconds and 4 git commands to generate.