From 4464a3efcf8dcddfb00d7db0c3add9a7acb6642e Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Thu, 3 Mar 2016 20:15:47 -0800 Subject: [PATCH] ART: Fix UTF test and monitor pool old chunks Zero-initialize buffers in utf_test. UTF conversion does not append a zero terminator, but the test uses strlen to check the byte count. Move to unique_ptr for storing old monitor-pool chunk data to fix a leak. Bug: 27156726 Change-Id: I14424c6f98cf47beab6243f83a335bd6a682c638 --- runtime/monitor_pool.cc | 2 +- runtime/monitor_pool.h | 3 ++- runtime/utf_test.cc | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime/monitor_pool.cc b/runtime/monitor_pool.cc index 2832e32dd..9e78cda19 100644 --- a/runtime/monitor_pool.cc +++ b/runtime/monitor_pool.cc @@ -51,7 +51,7 @@ void MonitorPool::AllocateChunk() { memcpy(new_backing, old_backing, sizeof(uintptr_t) * capacity_); monitor_chunks_.StoreRelaxed(new_backing); capacity_ = new_capacity; - old_chunk_arrays_.push_back(old_backing); + old_chunk_arrays_.push_back(std::unique_ptr(old_backing)); VLOG(monitor) << "Resizing to capacity " << capacity_; } } diff --git a/runtime/monitor_pool.h b/runtime/monitor_pool.h index 240ca6164..de553fc99 100644 --- a/runtime/monitor_pool.h +++ b/runtime/monitor_pool.h @@ -176,7 +176,8 @@ class MonitorPool { size_t capacity_ GUARDED_BY(Locks::allocated_monitor_ids_lock_); // To avoid race issues when resizing, we keep all the previous arrays. - std::vector old_chunk_arrays_ GUARDED_BY(Locks::allocated_monitor_ids_lock_); + std::vector> old_chunk_arrays_ + GUARDED_BY(Locks::allocated_monitor_ids_lock_); typedef TrackingAllocator Allocator; Allocator allocator_; diff --git a/runtime/utf_test.cc b/runtime/utf_test.cc index c67879b42..328492523 100644 --- a/runtime/utf_test.cc +++ b/runtime/utf_test.cc @@ -312,8 +312,8 @@ static void codePointToSurrogatePair(uint32_t code_point, uint16_t &first, uint1 } static void testConversions(uint16_t *buf, int char_count) { - char bytes_test[8], bytes_reference[8]; - uint16_t out_buf_test[4], out_buf_reference[4]; + char bytes_test[8] = { 0 }, bytes_reference[8] = { 0 }; + uint16_t out_buf_test[4] = { 0 }, out_buf_reference[4] = { 0 }; int byte_count_test, byte_count_reference; int char_count_test, char_count_reference; @@ -349,7 +349,7 @@ static void testConversions(uint16_t *buf, int char_count) { TEST_F(UtfTest, ExhaustiveBidirectionalCodePointCheck) { for (int codePoint = 0; codePoint <= 0x10ffff; ++codePoint) { - uint16_t buf[4]; + uint16_t buf[4] = { 0 }; if (codePoint <= 0xffff) { if (codePoint >= 0xd800 && codePoint <= 0xdfff) { // According to the Unicode standard, no character will ever -- 2.11.0