Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(862)

Unified Diff: test/cctest/test-api.cc

Issue 150213002: Make sure we delete[] what we got from new[], not one byte after it. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 0cab72374dc934677396b67b44457b8147e55d44..796127a438b17b294864b59099455d794c1c50c4 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -488,11 +488,14 @@ class TestResource: public String::ExternalStringResource {
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 @@ class TestAsciiResource: public String::ExternalAsciiStringResource {
size_t length() const {
return length_;
}
+
private:
+ const char* orig_data_;
const char* data_;
size_t length_;
int* counter_;
@@ -733,11 +738,11 @@ TEST(MakingExternalUnalignedAsciiString) {
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.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698