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

Side by Side Diff: runtime/vm/snapshot_test.cc

Issue 2620413002: Fix various memory leaks in unit tests detected by a new version of ASAN. (Closed)
Patch Set: Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "include/dart_tools_api.h" 7 #include "include/dart_tools_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/clustered_snapshot.h" 10 #include "vm/clustered_snapshot.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // Encode and decode the message. 132 // Encode and decode the message.
133 uint8_t* buffer = NULL; 133 uint8_t* buffer = NULL;
134 ApiMessageWriter writer(&buffer, &malloc_allocator); 134 ApiMessageWriter writer(&buffer, &malloc_allocator);
135 writer.WriteCMessage(root); 135 writer.WriteCMessage(root);
136 136
137 ApiMessageReader api_reader(buffer, writer.BytesWritten()); 137 ApiMessageReader api_reader(buffer, writer.BytesWritten());
138 Dart_CObject* new_root = api_reader.ReadMessage(); 138 Dart_CObject* new_root = api_reader.ReadMessage();
139 139
140 // Check that the two messages are the same. 140 // Check that the two messages are the same.
141 CompareDartCObjects(root, new_root); 141 CompareDartCObjects(root, new_root);
142
143 free(buffer);
142 } 144 }
143 145
144 146
145 static void ExpectEncodeFail(Dart_CObject* root) { 147 static void ExpectEncodeFail(Dart_CObject* root) {
146 uint8_t* buffer = NULL; 148 uint8_t* buffer = NULL;
147 ApiMessageWriter writer(&buffer, &malloc_allocator); 149 ApiMessageWriter writer(&buffer, &malloc_allocator);
148 const bool result = writer.WriteCMessage(root); 150 const bool result = writer.WriteCMessage(root);
149 EXPECT_EQ(false, result); 151 EXPECT_EQ(false, result);
152 free(buffer);
150 } 153 }
151 154
152 155
153 TEST_CASE(SerializeNull) { 156 TEST_CASE(SerializeNull) {
154 StackZone zone(thread); 157 StackZone zone(thread);
155 158
156 // Write snapshot with object content. 159 // Write snapshot with object content.
157 const Object& null_object = Object::Handle(); 160 const Object& null_object = Object::Handle();
158 uint8_t* buffer; 161 uint8_t* buffer;
159 MessageWriter writer(&buffer, &zone_allocator, true); 162 MessageWriter writer(&buffer, &zone_allocator, true);
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 } 1649 }
1647 1650
1648 { 1651 {
1649 // Use a script snapshot where a full snapshot is expected. 1652 // Use a script snapshot where a full snapshot is expected.
1650 char* error = NULL; 1653 char* error = NULL;
1651 Dart_Isolate isolate = Dart_CreateIsolate( 1654 Dart_Isolate isolate = Dart_CreateIsolate(
1652 "script-uri", "main", script_snapshot, NULL, NULL, &error); 1655 "script-uri", "main", script_snapshot, NULL, NULL, &error);
1653 EXPECT(isolate == NULL); 1656 EXPECT(isolate == NULL);
1654 EXPECT(error != NULL); 1657 EXPECT(error != NULL);
1655 EXPECT_SUBSTRING("got 'script', expected 'core'", error); 1658 EXPECT_SUBSTRING("got 'script', expected 'core'", error);
1659 free(error);
1656 } 1660 }
1657 1661
1658 { 1662 {
1659 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1663 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1660 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1664 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1661 1665
1662 // Use a full snapshot where a script snapshot is expected. 1666 // Use a full snapshot where a script snapshot is expected.
1663 Dart_Handle result = Dart_LoadScriptFromSnapshot(full_snapshot, size); 1667 Dart_Handle result = Dart_LoadScriptFromSnapshot(full_snapshot, size);
1664 EXPECT_ERROR(result, 1668 EXPECT_ERROR(result,
1665 "Dart_LoadScriptFromSnapshot expects parameter" 1669 "Dart_LoadScriptFromSnapshot expects parameter"
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2987 StackZone zone(Thread::Current()); 2991 StackZone zone(Thread::Current());
2988 uint8_t* buffer; 2992 uint8_t* buffer;
2989 MessageWriter writer(&buffer, &zone_allocator, true); 2993 MessageWriter writer(&buffer, &zone_allocator, true);
2990 writer.WriteInlinedObjectHeader(kOmittedObjectId); 2994 writer.WriteInlinedObjectHeader(kOmittedObjectId);
2991 // For performance, we'd like single-byte headers when ids are omitted. 2995 // For performance, we'd like single-byte headers when ids are omitted.
2992 // If this starts failing, consider renumbering the snapshot ids. 2996 // If this starts failing, consider renumbering the snapshot ids.
2993 EXPECT_EQ(1, writer.BytesWritten()); 2997 EXPECT_EQ(1, writer.BytesWritten());
2994 } 2998 }
2995 2999
2996 } // namespace dart 3000 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698