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

Unified Diff: runtime/vm/native_api_impl.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/message_handler_test.cc ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/native_api_impl.cc
diff --git a/runtime/vm/native_api_impl.cc b/runtime/vm/native_api_impl.cc
index 08a8daa56db39439c724e542068ac44e95496e95..4729375f4d50ac53663c948814e7ffb466648ce2 100644
--- a/runtime/vm/native_api_impl.cc
+++ b/runtime/vm/native_api_impl.cc
@@ -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(
« no previous file with comments | « runtime/vm/message_handler_test.cc ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698