Revision: 9205
Author:   [email protected]
Date:     Thu Sep  8 15:44:03 2011
Log: 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.

[email protected]

Review URL: http://codereview.chromium.org/7846022
Patch from Thiago Farina <[email protected]>.
http://code.google.com/p/v8/source/detail?r=9205

Modified:
 /branches/bleeding_edge/src/d8.cc
 /branches/bleeding_edge/src/d8.h

=======================================
--- /branches/bleeding_edge/src/d8.cc   Thu Sep  8 06:51:06 2011
+++ /branches/bleeding_edge/src/d8.cc   Thu Sep  8 15:44:03 2011
@@ -968,6 +968,16 @@
 #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 @@
 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 @@
       }
       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::WaitForThread() {
-  if (thread_.is_empty()) return;
+  if (thread_ == NULL) return;
   if (Shell::options.last_run) {
     thread_->Join();
+    thread_ = NULL;
   } else {
     done_semaphore_->Wait();
   }
=======================================
--- /branches/bleeding_edge/src/d8.h    Thu Sep  8 12:57:14 2011
+++ /branches/bleeding_edge/src/d8.h    Thu Sep  8 15:44:03 2011
@@ -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,10 +121,13 @@
 #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);
@@ -157,9 +159,9 @@
   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);

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to