Revision: 18937
Author:   [email protected]
Date:     Thu Jan 30 10:53:20 2014 UTC
Log: Make sure we delete[] what we got from new[], not one byte after it.

[email protected]

Review URL: https://codereview.chromium.org/150213002
http://code.google.com/p/v8/source/detail?r=18937

Modified:
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Wed Jan 29 15:29:58 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-api.cc Thu Jan 30 10:53:20 2014 UTC
@@ -488,11 +488,14 @@

 class TestAsciiResource: public String::ExternalAsciiStringResource {
  public:
-  explicit TestAsciiResource(const char* data, int* counter = NULL)
-    : data_(data), length_(strlen(data)), counter_(counter) { }
+ TestAsciiResource(const char* data, int* counter = NULL, size_t offset = 0)
+      : orig_data_(data),
+        data_(data + offset),
+        length_(strlen(data) - offset),
+        counter_(counter) { }

   ~TestAsciiResource() {
-    i::DeleteArray(data_);
+    i::DeleteArray(orig_data_);
     if (counter_ != NULL) ++*counter_;
   }

@@ -503,7 +506,9 @@
   size_t length() const {
     return length_;
   }
+
  private:
+  const char* orig_data_;
   const char* data_;
   size_t length_;
   int* counter_;
@@ -733,11 +738,11 @@
   int dispose_count = 0;
   const char* c_cons = "_abcdefghijklmnopqrstuvwxyz";
   bool success = cons->MakeExternal(
-      new TestAsciiResource(i::StrDup(c_cons) + 1, &dispose_count));
+      new TestAsciiResource(i::StrDup(c_cons), &dispose_count, 1));
   CHECK(success);
   const char* c_slice = "_bcdefghijklmnopqrstuvwxyz";
   success = slice->MakeExternal(
-      new TestAsciiResource(i::StrDup(c_slice) + 1, &dispose_count));
+      new TestAsciiResource(i::StrDup(c_slice), &dispose_count, 1));
   CHECK(success);

   // Trigger GCs and force evacuation.

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to