Skip to content

Commit 60904b8

Browse files
authored
Fix Valgrind uninitialized memory warnings (#12806)
Valgrind reported some uses of uninitialized memory when running the regression tests under it. This patch addresses the following valgrind reported issues: 1. LogBuffer flush: Syscall param write(buf) points to uninitialised byte(s) at Log::flush_thread_main(void*) by LogBuffer::LogBuffer(LogConfig const*, LogObject*, ...) 2. Cache test pwrite: Syscall param pwrite64(buf) points to uninitialised byte(s) at AIOThreadInfo::aio_thread_main(AIOThreadInfo*) by Stripe::Stripe(CacheDisk*, long, long, int, int)
1 parent 444a446 commit 60904b8

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

src/iocore/cache/CacheTest.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ test_RamCache(RegressionTest *t, RamCache *cache, const char *name, int64_t cach
566566
CryptoHash hash;
567567

568568
d->alloc(BUFFER_SIZE_INDEX_16K);
569+
memset(d->data(), 0, BUFFER_SIZE_FOR_INDEX(BUFFER_SIZE_INDEX_16K));
569570
data.push_back(make_ptr(d));
570571
hash.u64[0] = (static_cast<uint64_t>(i) << 32) + i;
571572
hash.u64[1] = (static_cast<uint64_t>(i) << 32) + i;
@@ -610,6 +611,7 @@ test_RamCache(RegressionTest *t, RamCache *cache, const char *name, int64_t cach
610611
if (!cache->get(&hash, &get_data)) {
611612
IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_thread());
612613
d->alloc(BUFFER_SIZE_INDEX_16K);
614+
memset(d->data(), 0, d->block_size());
613615
data.push_back(make_ptr(d));
614616
cache->put(&hash, data.back().get(), 1 << 15);
615617
if (i >= sample_size / 2) {
@@ -630,6 +632,7 @@ test_RamCache(RegressionTest *t, RamCache *cache, const char *name, int64_t cach
630632
if (!cache->get(&hash, &get_data)) {
631633
IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_thread());
632634
d->alloc(BUFFER_SIZE_INDEX_8K + (r[i] % 3));
635+
memset(d->data(), 0, d->block_size());
633636
data.push_back(make_ptr(d));
634637
cache->put(&hash, data.back().get(), d->block_size());
635638
if (i >= sample_size / 2) {

src/proxy/logging/LogBuffer.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ LogBuffer::LogBuffer(const LogConfig *cfg, LogObject *owner, size_t size, size_t
126126
}
127127
m_buffer = static_cast<char *>(align_pointer_forward(m_unaligned_buffer, buf_align));
128128

129+
memset(m_buffer, 0, size);
130+
129131
// add the header
130132
hdr_size = _add_buffer_header(cfg);
131133

0 commit comments

Comments
 (0)