X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fconsumer-metadata-cache.c;h=9cd99e5bf4d29f090baeb0c8326ce10ba880f2c7;hp=d8f5001f8b5efed8d12239a4856d46bde3939709;hb=6c1c0768320135c6936c371b09731851b508c023;hpb=6cd525e813795a1d5e38feac8dedf2c73ffb1274 diff --git a/src/common/consumer-metadata-cache.c b/src/common/consumer-metadata-cache.c index d8f5001f8..9cd99e5bf 100644 --- a/src/common/consumer-metadata-cache.c +++ b/src/common/consumer-metadata-cache.c @@ -17,6 +17,7 @@ */ #define _GNU_SOURCE +#define _LGPL_SOURCE #include #include #include @@ -46,14 +47,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 +62,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;