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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "lib/stacktrace.h" 10 #include "lib/stacktrace.h"
(...skipping 1762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 1773
1774 1774
1775 DART_EXPORT bool Dart_HasLivePorts() { 1775 DART_EXPORT bool Dart_HasLivePorts() {
1776 Isolate* isolate = Isolate::Current(); 1776 Isolate* isolate = Isolate::Current();
1777 ASSERT(isolate); 1777 ASSERT(isolate);
1778 NoSafepointScope no_safepoint_scope; 1778 NoSafepointScope no_safepoint_scope;
1779 return isolate->message_handler()->HasLivePorts(); 1779 return isolate->message_handler()->HasLivePorts();
1780 } 1780 }
1781 1781
1782 1782
1783 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 1783 static uint8_t* malloc_allocator(uint8_t* ptr,
1784 intptr_t old_size,
1785 intptr_t new_size) {
1784 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 1786 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
1785 return reinterpret_cast<uint8_t*>(new_ptr); 1787 return reinterpret_cast<uint8_t*>(new_ptr);
1786 } 1788 }
1787 1789
1788 1790
1791 static void malloc_deallocator(uint8_t* ptr) {
1792 free(reinterpret_cast<void*>(ptr));
1793 }
1794
1795
1789 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { 1796 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) {
1790 DARTSCOPE(Thread::Current()); 1797 DARTSCOPE(Thread::Current());
1791 API_TIMELINE_DURATION; 1798 API_TIMELINE_DURATION;
1792 NoSafepointScope no_safepoint_scope; 1799 NoSafepointScope no_safepoint_scope;
1793 if (port_id == ILLEGAL_PORT) { 1800 if (port_id == ILLEGAL_PORT) {
1794 return false; 1801 return false;
1795 } 1802 }
1796 1803
1797 // Smis and null can be sent without serialization. 1804 // Smis and null can be sent without serialization.
1798 RawObject* raw_obj = Api::UnwrapHandle(handle); 1805 RawObject* raw_obj = Api::UnwrapHandle(handle);
1799 if (ApiObjectConverter::CanConvert(raw_obj)) { 1806 if (ApiObjectConverter::CanConvert(raw_obj)) {
1800 return PortMap::PostMessage( 1807 return PortMap::PostMessage(
1801 new Message(port_id, raw_obj, Message::kNormalPriority)); 1808 new Message(port_id, raw_obj, Message::kNormalPriority));
1802 } 1809 }
1803 1810
1804 const Object& object = Object::Handle(Z, raw_obj); 1811 const Object& object = Object::Handle(Z, raw_obj);
1805 uint8_t* data = NULL; 1812 uint8_t* data = NULL;
1806 MessageWriter writer(&data, &allocator, false); 1813 MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false);
1807 writer.WriteMessage(object); 1814 writer.WriteMessage(object);
1808 intptr_t len = writer.BytesWritten(); 1815 intptr_t len = writer.BytesWritten();
1809 return PortMap::PostMessage( 1816 return PortMap::PostMessage(
1810 new Message(port_id, data, len, Message::kNormalPriority)); 1817 new Message(port_id, data, len, Message::kNormalPriority));
1811 } 1818 }
1812 1819
1813 1820
1814 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { 1821 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) {
1815 DARTSCOPE(Thread::Current()); 1822 DARTSCOPE(Thread::Current());
1816 CHECK_CALLBACK_STATE(T); 1823 CHECK_CALLBACK_STATE(T);
(...skipping 4998 matching lines...) Expand 10 before | Expand all | Expand 10 after
6815 } 6822 }
6816 6823
6817 6824
6818 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { 6825 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) {
6819 #ifndef PRODUCT 6826 #ifndef PRODUCT
6820 Profiler::DumpStackTrace(context); 6827 Profiler::DumpStackTrace(context);
6821 #endif 6828 #endif
6822 } 6829 }
6823 6830
6824 } // namespace dart 6831 } // namespace dart
OLDNEW
« 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