mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
Fix various memory leaks in unit tests detected by a new version of ASAN.
R=zra@google.com Review-Url: https://codereview.chromium.org/2620413002 .
This commit is contained in:
parent
443f2a0672
commit
cbf3eaeb90
7 changed files with 40 additions and 11 deletions
|
@ -96,9 +96,8 @@ void Benchmark::RunAll(const char* executable) {
|
|||
|
||||
|
||||
Dart_Isolate Benchmark::CreateIsolate(const uint8_t* buffer) {
|
||||
bin::IsolateData* isolate_data = new bin::IsolateData(NULL, NULL, NULL);
|
||||
char* err = NULL;
|
||||
isolate_ = Dart_CreateIsolate(NULL, NULL, buffer, NULL, isolate_data, &err);
|
||||
isolate_ = Dart_CreateIsolate(NULL, NULL, buffer, NULL, NULL, &err);
|
||||
EXPECT(isolate_ != NULL);
|
||||
free(err);
|
||||
return isolate_;
|
||||
|
@ -520,6 +519,9 @@ BENCHMARK_SIZE(CoreSnapshotSize) {
|
|||
const Snapshot* snapshot = Snapshot::SetupFromBuffer(isolate_snapshot_buffer);
|
||||
ASSERT(snapshot->kind() == Snapshot::kCore);
|
||||
benchmark->set_score(snapshot->length());
|
||||
|
||||
free(vm_isolate_snapshot_buffer);
|
||||
free(isolate_snapshot_buffer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -554,6 +556,9 @@ BENCHMARK_SIZE(StandaloneSnapshotSize) {
|
|||
const Snapshot* snapshot = Snapshot::SetupFromBuffer(isolate_snapshot_buffer);
|
||||
ASSERT(snapshot->kind() == Snapshot::kCore);
|
||||
benchmark->set_score(snapshot->length());
|
||||
|
||||
free(vm_isolate_snapshot_buffer);
|
||||
free(isolate_snapshot_buffer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -102,10 +102,13 @@ VM_TEST_CASE(CompileFunctionOnHelperThread) {
|
|||
ASSERT(isolate->background_compiler() != NULL);
|
||||
isolate->background_compiler()->CompileOptimized(func);
|
||||
Monitor* m = new Monitor();
|
||||
MonitorLocker ml(m);
|
||||
while (!func.HasOptimizedCode()) {
|
||||
ml.WaitWithSafepointCheck(thread, 1);
|
||||
{
|
||||
MonitorLocker ml(m);
|
||||
while (!func.HasOptimizedCode()) {
|
||||
ml.WaitWithSafepointCheck(thread, 1);
|
||||
}
|
||||
}
|
||||
delete m;
|
||||
BackgroundCompiler::Stop(isolate);
|
||||
}
|
||||
|
||||
|
|
|
@ -405,6 +405,7 @@ UNIT_TEST_CASE(MessageHandler_Run) {
|
|||
handler_peer.decrement_live_ports();
|
||||
EXPECT(!handler.HasLivePorts());
|
||||
PortMap::ClosePorts(&handler);
|
||||
delete[] ports;
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
|
|
@ -16,7 +16,9 @@ namespace dart {
|
|||
|
||||
// --- Message sending/receiving from native code ---
|
||||
|
||||
static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
|
||||
static uint8_t* malloc_allocator(uint8_t* ptr,
|
||||
intptr_t old_size,
|
||||
intptr_t new_size) {
|
||||
void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
|
||||
return reinterpret_cast<uint8_t*>(new_ptr);
|
||||
}
|
||||
|
@ -47,10 +49,13 @@ class IsolateSaver {
|
|||
|
||||
static bool PostCObjectHelper(Dart_Port port_id, Dart_CObject* message) {
|
||||
uint8_t* buffer = NULL;
|
||||
ApiMessageWriter writer(&buffer, allocator);
|
||||
ApiMessageWriter writer(&buffer, malloc_allocator);
|
||||
bool success = writer.WriteCMessage(message);
|
||||
|
||||
if (!success) return success;
|
||||
if (!success) {
|
||||
free(buffer);
|
||||
return success;
|
||||
}
|
||||
|
||||
// Post the message at the given port.
|
||||
return PortMap::PostMessage(new Message(
|
||||
|
|
|
@ -139,6 +139,8 @@ static void CheckEncodeDecodeMessage(Dart_CObject* root) {
|
|||
|
||||
// Check that the two messages are the same.
|
||||
CompareDartCObjects(root, new_root);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -147,6 +149,7 @@ static void ExpectEncodeFail(Dart_CObject* root) {
|
|||
ApiMessageWriter writer(&buffer, &malloc_allocator);
|
||||
const bool result = writer.WriteCMessage(root);
|
||||
EXPECT_EQ(false, result);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1653,6 +1656,7 @@ UNIT_TEST_CASE(MismatchedSnapshotKinds) {
|
|||
EXPECT(isolate == NULL);
|
||||
EXPECT(error != NULL);
|
||||
EXPECT_SUBSTRING("got 'script', expected 'core'", error);
|
||||
free(error);
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -91,7 +91,7 @@ class TimelineTestHelper : public AllStatic {
|
|||
event->Complete();
|
||||
}
|
||||
|
||||
static void Clear(TimelineEventEndlessRecorder* recorder) {
|
||||
static void Clear(TimelineEventRecorder* recorder) {
|
||||
ASSERT(recorder != NULL);
|
||||
recorder->Clear();
|
||||
}
|
||||
|
@ -343,6 +343,8 @@ TEST_CASE(TimelineEventCallbackRecorderBasic) {
|
|||
EXPECT_EQ(0, recorder->CountFor(TimelineEvent::kAsyncEnd));
|
||||
event->Complete();
|
||||
EXPECT_EQ(1, recorder->CountFor(TimelineEvent::kAsyncEnd));
|
||||
|
||||
delete recorder;
|
||||
}
|
||||
|
||||
|
||||
|
@ -466,6 +468,9 @@ TEST_CASE(TimelineAnalysis_ThreadBlockCount) {
|
|||
EXPECT(LabelMatch(it.Next(), "F"));
|
||||
EXPECT(!it.HasNext());
|
||||
}
|
||||
|
||||
TimelineTestHelper::Clear(recorder);
|
||||
delete recorder;
|
||||
}
|
||||
|
||||
|
||||
|
@ -502,6 +507,9 @@ TEST_CASE(TimelineRingRecorderJSONOrder) {
|
|||
const char* alpha = strstr(js.ToCString(), "Alpha");
|
||||
const char* beta = strstr(js.ToCString(), "Beta");
|
||||
EXPECT(alpha < beta);
|
||||
|
||||
TimelineTestHelper::Clear(recorder);
|
||||
delete recorder;
|
||||
}
|
||||
|
||||
|
||||
|
@ -674,6 +682,8 @@ TEST_CASE(TimelinePauses_Basic) {
|
|||
EXPECT_EQ(8, pauses.MaxExclusiveTime("a"));
|
||||
}
|
||||
TimelineTestHelper::Clear(recorder);
|
||||
|
||||
delete recorder;
|
||||
}
|
||||
|
||||
|
||||
|
@ -884,6 +894,8 @@ TEST_CASE(TimelinePauses_BeginEnd) {
|
|||
EXPECT(pauses.has_error());
|
||||
}
|
||||
TimelineTestHelper::Clear(recorder);
|
||||
|
||||
delete recorder;
|
||||
}
|
||||
|
||||
#endif // !PRODUCT
|
||||
|
|
|
@ -52,10 +52,9 @@ void TestCaseBase::RunAll() {
|
|||
|
||||
|
||||
Dart_Isolate TestCase::CreateIsolate(const uint8_t* buffer, const char* name) {
|
||||
bin::IsolateData* isolate_data = new bin::IsolateData(name, NULL, NULL);
|
||||
char* err;
|
||||
Dart_Isolate isolate =
|
||||
Dart_CreateIsolate(name, NULL, buffer, NULL, isolate_data, &err);
|
||||
Dart_CreateIsolate(name, NULL, buffer, NULL, NULL, &err);
|
||||
if (isolate == NULL) {
|
||||
OS::Print("Creation of isolate failed '%s'\n", err);
|
||||
free(err);
|
||||
|
|
Loading…
Reference in a new issue