Commit 2063e14c authored by vitalyr@chromium.org's avatar vitalyr@chromium.org

Release memory of semaphores and thread pointers by using 'delete' instead of SmartPointer.

As pointed out in: http://codereview.chromium.org/7754007/

SmartPointer expects an input allocated using new[] and deallocates it using delete[].
So using SmartPointer for deleting T* here is incorrect. Fix it now.

R=vitalyr@chromium.org

Review URL: http://codereview.chromium.org/7846022
Patch from Thiago Farina <tfarina@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9205 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b8cbe08f
...@@ -968,6 +968,16 @@ void ShellThread::Run() { ...@@ -968,6 +968,16 @@ void ShellThread::Run() {
#endif // V8_SHARED #endif // V8_SHARED
SourceGroup::~SourceGroup() {
delete next_semaphore_;
next_semaphore_ = NULL;
delete done_semaphore_;
done_semaphore_ = NULL;
delete thread_;
thread_ = NULL;
}
void SourceGroup::ExitShell(int exit_code) { void SourceGroup::ExitShell(int exit_code) {
// Use _exit instead of exit to avoid races between isolate // Use _exit instead of exit to avoid races between isolate
// threads and static destructors. // threads and static destructors.
...@@ -1037,7 +1047,7 @@ i::Thread::Options SourceGroup::GetThreadOptions() { ...@@ -1037,7 +1047,7 @@ i::Thread::Options SourceGroup::GetThreadOptions() {
void SourceGroup::ExecuteInThread() { void SourceGroup::ExecuteInThread() {
Isolate* isolate = Isolate::New(); Isolate* isolate = Isolate::New();
do { do {
if (!next_semaphore_.is_empty()) next_semaphore_->Wait(); if (next_semaphore_ != NULL) next_semaphore_->Wait();
{ {
Isolate::Scope iscope(isolate); Isolate::Scope iscope(isolate);
Locker lock(isolate); Locker lock(isolate);
...@@ -1049,15 +1059,15 @@ void SourceGroup::ExecuteInThread() { ...@@ -1049,15 +1059,15 @@ void SourceGroup::ExecuteInThread() {
} }
context.Dispose(); context.Dispose();
} }
if (!done_semaphore_.is_empty()) done_semaphore_->Signal(); if (done_semaphore_ != NULL) done_semaphore_->Signal();
} while (!Shell::options.last_run); } while (!Shell::options.last_run);
isolate->Dispose(); isolate->Dispose();
} }
void SourceGroup::StartExecuteInThread() { void SourceGroup::StartExecuteInThread() {
if (thread_.is_empty()) { if (thread_ == NULL) {
thread_ = i::SmartPointer<i::Thread>(new IsolateThread(this)); thread_ = new IsolateThread(this);
thread_->Start(); thread_->Start();
} }
next_semaphore_->Signal(); next_semaphore_->Signal();
...@@ -1065,9 +1075,10 @@ void SourceGroup::StartExecuteInThread() { ...@@ -1065,9 +1075,10 @@ void SourceGroup::StartExecuteInThread() {
void SourceGroup::WaitForThread() { void SourceGroup::WaitForThread() {
if (thread_.is_empty()) return; if (thread_ == NULL) return;
if (Shell::options.last_run) { if (Shell::options.last_run) {
thread_->Join(); thread_->Join();
thread_ = NULL;
} else { } else {
done_semaphore_->Wait(); done_semaphore_->Wait();
} }
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#ifndef V8_SHARED #ifndef V8_SHARED
#include "allocation.h" #include "allocation.h"
#include "hashmap.h" #include "hashmap.h"
#include "smart-pointer.h"
#include "v8.h" #include "v8.h"
#else #else
#include "../include/v8.h" #include "../include/v8.h"
...@@ -122,11 +121,14 @@ class SourceGroup { ...@@ -122,11 +121,14 @@ class SourceGroup {
#ifndef V8_SHARED #ifndef V8_SHARED
next_semaphore_(v8::internal::OS::CreateSemaphore(0)), next_semaphore_(v8::internal::OS::CreateSemaphore(0)),
done_semaphore_(v8::internal::OS::CreateSemaphore(0)), done_semaphore_(v8::internal::OS::CreateSemaphore(0)),
thread_(NULL),
#endif // V8_SHARED #endif // V8_SHARED
argv_(NULL), argv_(NULL),
begin_offset_(0), begin_offset_(0),
end_offset_(0) {} end_offset_(0) {}
~SourceGroup();
void Begin(char** argv, int offset) { void Begin(char** argv, int offset) {
argv_ = const_cast<const char**>(argv); argv_ = const_cast<const char**>(argv);
begin_offset_ = offset; begin_offset_ = offset;
...@@ -157,9 +159,9 @@ class SourceGroup { ...@@ -157,9 +159,9 @@ class SourceGroup {
static i::Thread::Options GetThreadOptions(); static i::Thread::Options GetThreadOptions();
void ExecuteInThread(); void ExecuteInThread();
i::SmartPointer<i::Semaphore> next_semaphore_; i::Semaphore* next_semaphore_;
i::SmartPointer<i::Semaphore> done_semaphore_; i::Semaphore* done_semaphore_;
i::SmartPointer<i::Thread> thread_; i::Thread* thread_;
#endif // V8_SHARED #endif // V8_SHARED
void ExitShell(int exit_code); void ExitShell(int exit_code);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment