From 3f1ea190fcd284107a9ea482b84914cda3a00c02 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Mon, 2 Jul 2012 12:15:23 +0000 Subject: [PATCH] Plug memory leak in Isolate. R=jkummerow@chromium.org BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/10702060 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11965 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/v8threads.cc | 23 ++++++++++++++++++++--- src/v8threads.h | 5 ++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/v8threads.cc b/src/v8threads.cc index fd8d536..32ea5e1 100644 --- a/src/v8threads.cc +++ b/src/v8threads.cc @@ -1,4 +1,4 @@ -// Copyright 2008 the V8 project authors. All rights reserved. +// Copyright 2012 the V8 project authors. All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: @@ -238,12 +238,18 @@ static int ArchiveSpacePerThread() { ThreadState::ThreadState(ThreadManager* thread_manager) : id_(ThreadId::Invalid()), terminate_on_restore_(false), + data_(NULL), next_(this), previous_(this), thread_manager_(thread_manager) { } +ThreadState::~ThreadState() { + DeleteArray(data_); +} + + void ThreadState::AllocateSpace() { data_ = NewArray(ArchiveSpacePerThread()); } @@ -306,8 +312,19 @@ ThreadManager::ThreadManager() ThreadManager::~ThreadManager() { delete mutex_; - delete free_anchor_; - delete in_use_anchor_; + DeleteThreadStateList(free_anchor_); + DeleteThreadStateList(in_use_anchor_); +} + + +void ThreadManager::DeleteThreadStateList(ThreadState* anchor) { + // The list starts and ends with the anchor. + for (ThreadState* current = anchor->next_; current != anchor;) { + ThreadState* next = current->next_; + delete current; + current = next; + } + delete anchor; } diff --git a/src/v8threads.h b/src/v8threads.h index a2aee4e..8dce860 100644 --- a/src/v8threads.h +++ b/src/v8threads.h @@ -1,4 +1,4 @@ -// Copyright 2008 the V8 project authors. All rights reserved. +// Copyright 2012 the V8 project authors. All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: @@ -57,6 +57,7 @@ class ThreadState { private: explicit ThreadState(ThreadManager* thread_manager); + ~ThreadState(); void AllocateSpace(); @@ -114,6 +115,8 @@ class ThreadManager { ThreadManager(); ~ThreadManager(); + void DeleteThreadStateList(ThreadState* anchor); + void EagerlyArchiveThread(); Mutex* mutex_; -- 2.7.4