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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 2629533002: Fix leak of message snapshot buffer when attempting to send an illegal object. (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/benchmark_test.cc ('k') | runtime/vm/dart_api_message.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index 8ff2deb5d67f79af18fbb3ae1cc7074d99718e6e..38123f713854875c7fc62e68a45e23e7b5695f8d 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -1780,12 +1780,19 @@ DART_EXPORT bool Dart_HasLivePorts() {
}
-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);
}
+static void malloc_deallocator(uint8_t* ptr) {
+ free(reinterpret_cast<void*>(ptr));
+}
+
+
DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) {
DARTSCOPE(Thread::Current());
API_TIMELINE_DURATION;
@@ -1803,7 +1810,7 @@ DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) {
const Object& object = Object::Handle(Z, raw_obj);
uint8_t* data = NULL;
- MessageWriter writer(&data, &allocator, false);
+ MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false);
writer.WriteMessage(object);
intptr_t len = writer.BytesWritten();
return PortMap::PostMessage(
« no previous file with comments | « runtime/vm/benchmark_test.cc ('k') | runtime/vm/dart_api_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698