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

Side by Side Diff: runtime/vm/isolate.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/datastream.h ('k') | runtime/vm/parser.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) 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 "vm/isolate.h" 5 #include "vm/isolate.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/text_buffer.h" 10 #include "platform/text_buffer.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 void VisitIsolate(Isolate* isolate) { ASSERT(isolate->origin_id() != id_); } 94 void VisitIsolate(Isolate* isolate) { ASSERT(isolate->origin_id() != id_); }
95 95
96 private: 96 private:
97 Dart_Port id_; 97 Dart_Port id_;
98 DISALLOW_COPY_AND_ASSIGN(VerifyOriginId); 98 DISALLOW_COPY_AND_ASSIGN(VerifyOriginId);
99 }; 99 };
100 #endif 100 #endif
101 101
102 102
103 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 103 static uint8_t* malloc_allocator(uint8_t* ptr,
104 intptr_t old_size,
105 intptr_t new_size) {
104 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 106 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
105 return reinterpret_cast<uint8_t*>(new_ptr); 107 return reinterpret_cast<uint8_t*>(new_ptr);
106 } 108 }
107 109
110 static void malloc_deallocator(uint8_t* ptr) {
111 free(reinterpret_cast<void*>(ptr));
112 }
113
108 114
109 static void SerializeObject(const Instance& obj, 115 static void SerializeObject(const Instance& obj,
110 uint8_t** obj_data, 116 uint8_t** obj_data,
111 intptr_t* obj_len, 117 intptr_t* obj_len,
112 bool allow_any_object) { 118 bool allow_any_object) {
113 MessageWriter writer(obj_data, &allocator, allow_any_object); 119 MessageWriter writer(obj_data, &malloc_allocator, &malloc_deallocator,
120 allow_any_object);
114 writer.WriteMessage(obj); 121 writer.WriteMessage(obj);
115 *obj_len = writer.BytesWritten(); 122 *obj_len = writer.BytesWritten();
116 } 123 }
117 124
118 // TODO(zra): Allocation of Message objects should be centralized. 125 // TODO(zra): Allocation of Message objects should be centralized.
119 static Message* SerializeMessage(Dart_Port dest_port, const Instance& obj) { 126 static Message* SerializeMessage(Dart_Port dest_port, const Instance& obj) {
120 if (ApiObjectConverter::CanConvert(obj.raw())) { 127 if (ApiObjectConverter::CanConvert(obj.raw())) {
121 return new Message(dest_port, obj.raw(), Message::kNormalPriority); 128 return new Message(dest_port, obj.raw(), Message::kNormalPriority);
122 } else { 129 } else {
123 uint8_t* obj_data; 130 uint8_t* obj_data;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 Object& element = Object::Handle(); 193 Object& element = Object::Handle();
187 194
188 element = Smi::New(Message::kIsolateLibOOBMsg); 195 element = Smi::New(Message::kIsolateLibOOBMsg);
189 msg.SetAt(0, element); 196 msg.SetAt(0, element);
190 element = Smi::New(msg_id); 197 element = Smi::New(msg_id);
191 msg.SetAt(1, element); 198 msg.SetAt(1, element);
192 element = Capability::New(capability); 199 element = Capability::New(capability);
193 msg.SetAt(2, element); 200 msg.SetAt(2, element);
194 201
195 uint8_t* data = NULL; 202 uint8_t* data = NULL;
196 MessageWriter writer(&data, &allocator, false); 203 MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false);
197 writer.WriteMessage(msg); 204 writer.WriteMessage(msg);
198 205
199 PortMap::PostMessage(new Message(main_port(), data, writer.BytesWritten(), 206 PortMap::PostMessage(new Message(main_port(), data, writer.BytesWritten(),
200 Message::kOOBPriority)); 207 Message::kOOBPriority));
201 } 208 }
202 209
203 210
204 class IsolateMessageHandler : public MessageHandler { 211 class IsolateMessageHandler : public MessageHandler {
205 public: 212 public:
206 explicit IsolateMessageHandler(Isolate* isolate); 213 explicit IsolateMessageHandler(Isolate* isolate);
(...skipping 2342 matching lines...) Expand 10 before | Expand all | Expand 10 after
2549 cap.value.as_capability.id = terminate_capability(); 2556 cap.value.as_capability.id = terminate_capability();
2550 list_values[2] = &cap; 2557 list_values[2] = &cap;
2551 2558
2552 Dart_CObject imm; 2559 Dart_CObject imm;
2553 imm.type = Dart_CObject_kInt32; 2560 imm.type = Dart_CObject_kInt32;
2554 imm.value.as_int32 = Isolate::kImmediateAction; 2561 imm.value.as_int32 = Isolate::kImmediateAction;
2555 list_values[3] = &imm; 2562 list_values[3] = &imm;
2556 2563
2557 { 2564 {
2558 uint8_t* buffer = NULL; 2565 uint8_t* buffer = NULL;
2559 ApiMessageWriter writer(&buffer, allocator); 2566 ApiMessageWriter writer(&buffer, &malloc_allocator);
2560 bool success = writer.WriteCMessage(&kill_msg); 2567 bool success = writer.WriteCMessage(&kill_msg);
2561 ASSERT(success); 2568 ASSERT(success);
2562 2569
2563 // Post the message at the given port. 2570 // Post the message at the given port.
2564 success = PortMap::PostMessage(new Message( 2571 success = PortMap::PostMessage(new Message(
2565 main_port(), buffer, writer.BytesWritten(), Message::kOOBPriority)); 2572 main_port(), buffer, writer.BytesWritten(), Message::kOOBPriority));
2566 ASSERT(success); 2573 ASSERT(success);
2567 } 2574 }
2568 } 2575 }
2569 2576
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
2967 void IsolateSpawnState::DecrementSpawnCount() { 2974 void IsolateSpawnState::DecrementSpawnCount() {
2968 ASSERT(spawn_count_monitor_ != NULL); 2975 ASSERT(spawn_count_monitor_ != NULL);
2969 ASSERT(spawn_count_ != NULL); 2976 ASSERT(spawn_count_ != NULL);
2970 MonitorLocker ml(spawn_count_monitor_); 2977 MonitorLocker ml(spawn_count_monitor_);
2971 ASSERT(*spawn_count_ > 0); 2978 ASSERT(*spawn_count_ > 0);
2972 *spawn_count_ = *spawn_count_ - 1; 2979 *spawn_count_ = *spawn_count_ - 1;
2973 ml.Notify(); 2980 ml.Notify();
2974 } 2981 }
2975 2982
2976 } // namespace dart 2983 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/datastream.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698