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

Side by Side Diff: runtime/bin/dartutils.cc

Issue 21022008: Fixed memory leaks in runtime/bin/dartutils.cc (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "bin/dartutils.h" 5 #include "bin/dartutils.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 9
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 382
383 383
384 Dart_Handle DartUtils::ReadStringFromFile(const char* filename) { 384 Dart_Handle DartUtils::ReadStringFromFile(const char* filename) {
385 const char* error_msg = NULL; 385 const char* error_msg = NULL;
386 intptr_t len; 386 intptr_t len;
387 const uint8_t* text_buffer = ReadFileFully(filename, &len, &error_msg); 387 const uint8_t* text_buffer = ReadFileFully(filename, &len, &error_msg);
388 if (text_buffer == NULL) { 388 if (text_buffer == NULL) {
389 return Dart_Error(error_msg); 389 return Dart_Error(error_msg);
390 } 390 }
391 Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len); 391 Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len);
392 free(const_cast<uint8_t *>(text_buffer));
392 return str; 393 return str;
393 } 394 }
394 395
395 396
396 Dart_Handle DartUtils::SetWorkingDirectory(Dart_Handle builtin_lib) { 397 Dart_Handle DartUtils::SetWorkingDirectory(Dart_Handle builtin_lib) {
397 Dart_Handle directory = NewString(original_working_directory); 398 Dart_Handle directory = NewString(original_working_directory);
398 return SingleArgDart_Invoke(builtin_lib, "_setWorkingDirectory", directory); 399 return SingleArgDart_Invoke(builtin_lib, "_setWorkingDirectory", directory);
399 } 400 }
400 401
401 402
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 } 588 }
588 Dart_Handle script_path = DartUtils::FilePathFromUri(resolved_script_uri, 589 Dart_Handle script_path = DartUtils::FilePathFromUri(resolved_script_uri,
589 builtin_lib); 590 builtin_lib);
590 if (Dart_IsError(script_path)) { 591 if (Dart_IsError(script_path)) {
591 return script_path; 592 return script_path;
592 } 593 }
593 const char* script_path_cstr; 594 const char* script_path_cstr;
594 Dart_StringToCString(script_path, &script_path_cstr); 595 Dart_StringToCString(script_path, &script_path_cstr);
595 const char* error_msg = NULL; 596 const char* error_msg = NULL;
596 intptr_t len; 597 intptr_t len;
597 const uint8_t* text_buffer = ReadFileFully(script_path_cstr, 598 const uint8_t* buffer = ReadFileFully(script_path_cstr,
598 &len, 599 &len,
599 &error_msg); 600 &error_msg);
600 if (text_buffer == NULL) { 601 if (buffer == NULL) {
601 return Dart_Error(error_msg); 602 return Dart_Error(error_msg);
602 } 603 }
603 bool is_snapshot = false; 604 bool is_snapshot = false;
604 text_buffer = SniffForMagicNumber(text_buffer, &len, &is_snapshot); 605 const uint8_t *payload = SniffForMagicNumber(buffer, &len, &is_snapshot);
606 Dart_Handle returnValue;
605 if (is_snapshot) { 607 if (is_snapshot) {
606 return Dart_LoadScriptFromSnapshot(text_buffer, len); 608 returnValue = Dart_LoadScriptFromSnapshot(payload, len);
607 } else { 609 } else {
608 Dart_Handle source = Dart_NewStringFromUTF8(text_buffer, len); 610 Dart_Handle source = Dart_NewStringFromUTF8(buffer, len);
609 if (Dart_IsError(source)) { 611 if (Dart_IsError(source)) {
610 return source; 612 returnValue = source;
613 } else {
614 returnValue = Dart_LoadScript(resolved_script_uri, source, 0, 0);
611 } 615 }
612 return Dart_LoadScript(resolved_script_uri, source, 0, 0);
613 } 616 }
617 free(const_cast<uint8_t *>(buffer));
618 return returnValue;
614 } 619 }
615 620
616 621
617 Dart_Handle DartUtils::LoadSource(CommandLineOptions* url_mapping, 622 Dart_Handle DartUtils::LoadSource(CommandLineOptions* url_mapping,
618 Dart_Handle library, 623 Dart_Handle library,
619 Dart_Handle url, 624 Dart_Handle url,
620 Dart_LibraryTag tag, 625 Dart_LibraryTag tag,
621 const char* url_string) { 626 const char* url_string) {
622 bool is_http_scheme_url = DartUtils::IsHttpSchemeURL(url_string); 627 bool is_http_scheme_url = DartUtils::IsHttpSchemeURL(url_string);
623 if (url_mapping != NULL && IsDartSchemeURL(url_string)) { 628 if (url_mapping != NULL && IsDartSchemeURL(url_string)) {
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 new CObjectString(CObject::NewString(os_error->message())); 1003 new CObjectString(CObject::NewString(os_error->message()));
999 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 1004 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
1000 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 1005 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
1001 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 1006 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
1002 result->SetAt(2, error_message); 1007 result->SetAt(2, error_message);
1003 return result; 1008 return result;
1004 } 1009 }
1005 1010
1006 } // namespace bin 1011 } // namespace bin
1007 } // namespace dart 1012 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698