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
This commit is contained in:
parent
b8cbe08fcc
commit
2063e14c15
21
src/d8.cc
21
src/d8.cc
@ -968,6 +968,16 @@ void ShellThread::Run() {
|
||||
#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) {
|
||||
// Use _exit instead of exit to avoid races between isolate
|
||||
// threads and static destructors.
|
||||
@ -1037,7 +1047,7 @@ i::Thread::Options SourceGroup::GetThreadOptions() {
|
||||
void SourceGroup::ExecuteInThread() {
|
||||
Isolate* isolate = Isolate::New();
|
||||
do {
|
||||
if (!next_semaphore_.is_empty()) next_semaphore_->Wait();
|
||||
if (next_semaphore_ != NULL) next_semaphore_->Wait();
|
||||
{
|
||||
Isolate::Scope iscope(isolate);
|
||||
Locker lock(isolate);
|
||||
@ -1049,15 +1059,15 @@ void SourceGroup::ExecuteInThread() {
|
||||
}
|
||||
context.Dispose();
|
||||
}
|
||||
if (!done_semaphore_.is_empty()) done_semaphore_->Signal();
|
||||
if (done_semaphore_ != NULL) done_semaphore_->Signal();
|
||||
} while (!Shell::options.last_run);
|
||||
isolate->Dispose();
|
||||
}
|
||||
|
||||
|
||||
void SourceGroup::StartExecuteInThread() {
|
||||
if (thread_.is_empty()) {
|
||||
thread_ = i::SmartPointer<i::Thread>(new IsolateThread(this));
|
||||
if (thread_ == NULL) {
|
||||
thread_ = new IsolateThread(this);
|
||||
thread_->Start();
|
||||
}
|
||||
next_semaphore_->Signal();
|
||||
@ -1065,9 +1075,10 @@ void SourceGroup::StartExecuteInThread() {
|
||||
|
||||
|
||||
void SourceGroup::WaitForThread() {
|
||||
if (thread_.is_empty()) return;
|
||||
if (thread_ == NULL) return;
|
||||
if (Shell::options.last_run) {
|
||||
thread_->Join();
|
||||
thread_ = NULL;
|
||||
} else {
|
||||
done_semaphore_->Wait();
|
||||
}
|
||||
|
10
src/d8.h
10
src/d8.h
@ -31,7 +31,6 @@
|
||||
#ifndef V8_SHARED
|
||||
#include "allocation.h"
|
||||
#include "hashmap.h"
|
||||
#include "smart-pointer.h"
|
||||
#include "v8.h"
|
||||
#else
|
||||
#include "../include/v8.h"
|
||||
@ -122,11 +121,14 @@ class SourceGroup {
|
||||
#ifndef V8_SHARED
|
||||
next_semaphore_(v8::internal::OS::CreateSemaphore(0)),
|
||||
done_semaphore_(v8::internal::OS::CreateSemaphore(0)),
|
||||
thread_(NULL),
|
||||
#endif // V8_SHARED
|
||||
argv_(NULL),
|
||||
begin_offset_(0),
|
||||
end_offset_(0) {}
|
||||
|
||||
~SourceGroup();
|
||||
|
||||
void Begin(char** argv, int offset) {
|
||||
argv_ = const_cast<const char**>(argv);
|
||||
begin_offset_ = offset;
|
||||
@ -157,9 +159,9 @@ class SourceGroup {
|
||||
static i::Thread::Options GetThreadOptions();
|
||||
void ExecuteInThread();
|
||||
|
||||
i::SmartPointer<i::Semaphore> next_semaphore_;
|
||||
i::SmartPointer<i::Semaphore> done_semaphore_;
|
||||
i::SmartPointer<i::Thread> thread_;
|
||||
i::Semaphore* next_semaphore_;
|
||||
i::Semaphore* done_semaphore_;
|
||||
i::Thread* thread_;
|
||||
#endif // V8_SHARED
|
||||
|
||||
void ExitShell(int exit_code);
|
||||
|
Loading…
Reference in New Issue
Block a user