summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ian Rogers <irogers@google.com> 2013-04-18 20:09:02 -0700
committer Ian Rogers <irogers@google.com> 2013-04-18 20:09:02 -0700
commite7a5b7d3fcc3af100fec13af057eecaff1037f2c (patch)
tree17c679d40aaaea7ddb53fdc61494c8d243af9ce5
parent1bd4b4ca7f4f44c55ded050e5a6be09811e1b283 (diff)
Fix memory leak of and use without initialization.
Arena allocator's empty arena needs to be released in a destructor, this removes the neeed for Reset. The DataflowIterator needs to clear changed_ upon construction to avoid use without initialization. Change-Id: I56e3cb8c3e06c08ab0ff42447bd6e05792fc70af
-rw-r--r--src/compiler/dex/arena_allocator.cc25
-rw-r--r--src/compiler/dex/arena_allocator.h2
-rw-r--r--src/compiler/dex/dataflow_iterator.h5
-rw-r--r--src/compiler/dex/frontend.cc2
4 files changed, 17 insertions, 17 deletions
diff --git a/src/compiler/dex/arena_allocator.cc b/src/compiler/dex/arena_allocator.cc
index 2db8445be0..7f1bfb386d 100644
--- a/src/compiler/dex/arena_allocator.cc
+++ b/src/compiler/dex/arena_allocator.cc
@@ -50,6 +50,18 @@ ArenaAllocator::ArenaAllocator(size_t default_size)
num_arena_blocks_++;
}
+ArenaAllocator::~ArenaAllocator() {
+ // Reclaim all the arena blocks allocated so far.
+ ArenaMemBlock* head = arena_head_;
+ while (head != NULL) {
+ ArenaMemBlock* p = head;
+ head = head->next;
+ free(p);
+ }
+ arena_head_ = current_arena_ = NULL;
+ num_arena_blocks_ = 0;
+}
+
// Return an arena with no storage for use as a sentinal.
ArenaAllocator::ArenaMemBlock* ArenaAllocator::EmptyArena() {
ArenaMemBlock* res = static_cast<ArenaMemBlock*>(malloc(sizeof(ArenaMemBlock)));
@@ -91,19 +103,6 @@ void* ArenaAllocator::NewMem(size_t size, bool zero, ArenaAllocKind kind) {
return ptr;
}
-// Reclaim all the arena blocks allocated so far.
-void ArenaAllocator::ArenaReset() {
- ArenaMemBlock* head = arena_head_;
- while (head != NULL) {
- ArenaMemBlock* p = head;
- head = head->next;
- free(p);
- }
- // We must always have an arena. Create a zero-length one.
- arena_head_ = current_arena_ = EmptyArena();
- num_arena_blocks_ = 1;
-}
-
// Dump memory usage stats.
void ArenaAllocator::DumpMemStats(std::ostream& os) const {
size_t total = 0;
diff --git a/src/compiler/dex/arena_allocator.h b/src/compiler/dex/arena_allocator.h
index 53d1a1b7e4..26294b6cbc 100644
--- a/src/compiler/dex/arena_allocator.h
+++ b/src/compiler/dex/arena_allocator.h
@@ -47,8 +47,8 @@ class ArenaAllocator {
};
ArenaAllocator(size_t default_size = ARENA_DEFAULT_BLOCK_SIZE);
+ ~ArenaAllocator();
void* NewMem(size_t size, bool zero, ArenaAllocKind kind);
- void ArenaReset();
size_t BytesAllocated() {
return malloc_bytes_;
}
diff --git a/src/compiler/dex/dataflow_iterator.h b/src/compiler/dex/dataflow_iterator.h
index 7d32dfc218..a4b38bd80f 100644
--- a/src/compiler/dex/dataflow_iterator.h
+++ b/src/compiler/dex/dataflow_iterator.h
@@ -66,7 +66,10 @@ namespace art {
is_iterative_(is_iterative),
start_idx_(start_idx),
end_idx_(end_idx),
- reverse_(reverse) {}
+ reverse_(reverse),
+ block_id_list_(NULL),
+ idx_(0),
+ changed_(false) {}
virtual BasicBlock* NextBody(bool had_change);
diff --git a/src/compiler/dex/frontend.cc b/src/compiler/dex/frontend.cc
index 6f4ee6c5b0..b212e5bd0e 100644
--- a/src/compiler/dex/frontend.cc
+++ b/src/compiler/dex/frontend.cc
@@ -249,8 +249,6 @@ static CompiledMethod* CompileMethod(CompilerDriver& compiler,
}
}
- cu->arena.ArenaReset();
-
return result;
}