Valgrind cleanliness, part 5: Delete extensions on exit.
authorsvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 29 Mar 2012 09:45:46 +0000 (09:45 +0000)
committersvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 29 Mar 2012 09:45:46 +0000 (09:45 +0000)
This fixes 4 leaks, returning 196 bytes of lost memory.

Review URL: https://chromiumcodereview.appspot.com/9864034

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11184 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/api.cc
src/api.h
src/extensions/externalize-string-extension.cc
src/extensions/gc-extension.cc
src/v8.cc

index 1feaf5a20c5af166c7f2c865c1c78e257c702bd2..eab7c8072a3c7cb221d92ab0f1dd52d470084f67 100644 (file)
@@ -512,6 +512,16 @@ void RegisteredExtension::Register(RegisteredExtension* that) {
 }
 
 
+void RegisteredExtension::UnregisterAll() {
+  RegisteredExtension* re = first_extension_;
+  while (re != NULL) {
+    RegisteredExtension* next = re->next();
+    delete re;
+    re = next;
+  }
+}
+
+
 void RegisterExtension(Extension* that) {
   RegisteredExtension* extension = new RegisteredExtension(that);
   RegisteredExtension::Register(extension);
index 89cf0c864cc811124360f76fbf4f17e269d83e6f..3ad57f465763a740a70b9fbd5d6fa189c4518ead 100644 (file)
--- a/src/api.h
+++ b/src/api.h
@@ -146,6 +146,7 @@ class RegisteredExtension {
  public:
   explicit RegisteredExtension(Extension* extension);
   static void Register(RegisteredExtension* that);
+  static void UnregisterAll();
   Extension* extension() { return extension_; }
   RegisteredExtension* next() { return next_; }
   RegisteredExtension* next_auto() { return next_auto_; }
index 9fbf3298189acdace28f175af3f855b5ae13bd68..50d876136f2d08514eb446ccf6ac4652ed68d384 100644 (file)
@@ -133,11 +133,8 @@ v8::Handle<v8::Value> ExternalizeStringExtension::IsAscii(
 
 
 void ExternalizeStringExtension::Register() {
-  static ExternalizeStringExtension* externalize_extension = NULL;
-  if (externalize_extension == NULL)
-    externalize_extension = new ExternalizeStringExtension;
-  static v8::DeclareExtension externalize_extension_declaration(
-      externalize_extension);
+  static ExternalizeStringExtension externalize_extension;
+  static v8::DeclareExtension declaration(&externalize_extension);
 }
 
 } }  // namespace v8::internal
index 573797e174aae23ba2ee800e972fd8fa5835c4a0..f921552aaaa7fa2c3156cb35c5904bfbe1d7f9fc 100644 (file)
@@ -46,9 +46,8 @@ v8::Handle<v8::Value> GCExtension::GC(const v8::Arguments& args) {
 
 
 void GCExtension::Register() {
-  static GCExtension* gc_extension = NULL;
-  if (gc_extension == NULL) gc_extension = new GCExtension();
-  static v8::DeclareExtension gc_extension_declaration(gc_extension);
+  static GCExtension gc_extension;
+  static v8::DeclareExtension declaration(&gc_extension);
 }
 
 } }  // namespace v8::internal
index 1280f1ce6863893b5f67fb950dd2ee710eb3d9c3..c6c4ecbd7f7c2a9d4933a1d02e357783806a219c 100644 (file)
--- a/src/v8.cc
+++ b/src/v8.cc
@@ -106,6 +106,7 @@ void V8::TearDown() {
 
   ElementsAccessor::TearDown();
   LOperand::TearDownCaches();
+  RegisteredExtension::UnregisterAll();
 
   isolate->TearDown();
   delete isolate;