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

Side by Side Diff: runtime/lib/vmservice.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/lib/isolate.cc ('k') | runtime/vm/benchmark_test.cc » ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 #include "vm/dart_api_impl.h" 6 #include "vm/dart_api_impl.h"
7 #include "vm/datastream.h" 7 #include "vm/datastream.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/flags.h" 9 #include "vm/flags.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
11 #include "vm/message.h" 11 #include "vm/message.h"
12 #include "vm/message_handler.h" 12 #include "vm/message_handler.h"
13 #include "vm/native_entry.h" 13 #include "vm/native_entry.h"
14 #include "vm/object.h" 14 #include "vm/object.h"
15 #include "vm/port.h" 15 #include "vm/port.h"
16 #include "vm/service_event.h" 16 #include "vm/service_event.h"
17 #include "vm/service_isolate.h" 17 #include "vm/service_isolate.h"
18 #include "vm/symbols.h" 18 #include "vm/symbols.h"
19 19
20 namespace dart { 20 namespace dart {
21 21
22 DECLARE_FLAG(bool, trace_service); 22 DECLARE_FLAG(bool, trace_service);
23 23
24 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 24 static uint8_t* malloc_allocator(uint8_t* ptr,
25 intptr_t old_size,
26 intptr_t new_size) {
25 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 27 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
26 return reinterpret_cast<uint8_t*>(new_ptr); 28 return reinterpret_cast<uint8_t*>(new_ptr);
27 } 29 }
28 30
31 static void malloc_deallocator(uint8_t* ptr) {
32 free(reinterpret_cast<void*>(ptr));
33 }
34
29 35
30 #ifndef PRODUCT 36 #ifndef PRODUCT
31 class RegisterRunningIsolatesVisitor : public IsolateVisitor { 37 class RegisterRunningIsolatesVisitor : public IsolateVisitor {
32 public: 38 public:
33 explicit RegisterRunningIsolatesVisitor(Thread* thread) 39 explicit RegisterRunningIsolatesVisitor(Thread* thread)
34 : IsolateVisitor(), 40 : IsolateVisitor(),
35 register_function_(Function::Handle(thread->zone())), 41 register_function_(Function::Handle(thread->zone())),
36 service_isolate_(thread->isolate()) { 42 service_isolate_(thread->isolate()) {
37 ASSERT(ServiceIsolate::IsServiceIsolate(Isolate::Current())); 43 ASSERT(ServiceIsolate::IsServiceIsolate(Isolate::Current()));
38 // Get library. 44 // Get library.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 94 }
89 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, sp, arguments->NativeArgAt(0)); 95 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, sp, arguments->NativeArgAt(0));
90 GET_NON_NULL_NATIVE_ARGUMENT(Array, message, arguments->NativeArgAt(1)); 96 GET_NON_NULL_NATIVE_ARGUMENT(Array, message, arguments->NativeArgAt(1));
91 97
92 // Set the type of the OOB message. 98 // Set the type of the OOB message.
93 message.SetAt(0, 99 message.SetAt(0,
94 Smi::Handle(thread->zone(), Smi::New(Message::kServiceOOBMsg))); 100 Smi::Handle(thread->zone(), Smi::New(Message::kServiceOOBMsg)));
95 101
96 // Serialize message. 102 // Serialize message.
97 uint8_t* data = NULL; 103 uint8_t* data = NULL;
98 MessageWriter writer(&data, &allocator, false); 104 MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false);
99 writer.WriteMessage(message); 105 writer.WriteMessage(message);
100 106
101 // TODO(turnidge): Throw an exception when the return value is false? 107 // TODO(turnidge): Throw an exception when the return value is false?
102 bool result = PortMap::PostMessage( 108 bool result = PortMap::PostMessage(
103 new Message(sp.Id(), data, writer.BytesWritten(), Message::kOOBPriority)); 109 new Message(sp.Id(), data, writer.BytesWritten(), Message::kOOBPriority));
104 return Bool::Get(result).raw(); 110 return Bool::Get(result).raw();
105 } 111 }
106 112
107 113
108 DEFINE_NATIVE_ENTRY(VMService_SendRootServiceMessage, 1) { 114 DEFINE_NATIVE_ENTRY(VMService_SendRootServiceMessage, 1) {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 ServiceEvent spawn_event(NULL, ServiceEvent::kIsolateSpawn); 471 ServiceEvent spawn_event(NULL, ServiceEvent::kIsolateSpawn);
466 spawn_event.set_spawn_token(&token); 472 spawn_event.set_spawn_token(&token);
467 spawn_event.set_spawn_error(&String::Cast(result)); 473 spawn_event.set_spawn_error(&String::Cast(result));
468 Service::HandleEvent(&spawn_event); 474 Service::HandleEvent(&spawn_event);
469 } 475 }
470 #endif // PRODUCT 476 #endif // PRODUCT
471 return Object::null(); 477 return Object::null();
472 } 478 }
473 479
474 } // namespace dart 480 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/vm/benchmark_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698