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

Unified 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, 5 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/dartutils.cc
diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc
index 5de42acc9f4ca06374055d9840a76cf7dd0baea4..a90694d8733b4dd010cba34fa359402940967b9b 100644
--- a/runtime/bin/dartutils.cc
+++ b/runtime/bin/dartutils.cc
@@ -389,6 +389,7 @@ Dart_Handle DartUtils::ReadStringFromFile(const char* filename) {
return Dart_Error(error_msg);
}
Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len);
+ free(const_cast<uint8_t *>(text_buffer));
return str;
}
@@ -594,23 +595,27 @@ Dart_Handle DartUtils::LoadScript(const char* script_uri,
Dart_StringToCString(script_path, &script_path_cstr);
const char* error_msg = NULL;
intptr_t len;
- const uint8_t* text_buffer = ReadFileFully(script_path_cstr,
- &len,
- &error_msg);
- if (text_buffer == NULL) {
+ const uint8_t* buffer = ReadFileFully(script_path_cstr,
+ &len,
+ &error_msg);
+ if (buffer == NULL) {
return Dart_Error(error_msg);
}
bool is_snapshot = false;
- text_buffer = SniffForMagicNumber(text_buffer, &len, &is_snapshot);
+ const uint8_t *payload = SniffForMagicNumber(buffer, &len, &is_snapshot);
+ Dart_Handle returnValue;
if (is_snapshot) {
- return Dart_LoadScriptFromSnapshot(text_buffer, len);
+ returnValue = Dart_LoadScriptFromSnapshot(payload, len);
} else {
- Dart_Handle source = Dart_NewStringFromUTF8(text_buffer, len);
+ Dart_Handle source = Dart_NewStringFromUTF8(buffer, len);
if (Dart_IsError(source)) {
- return source;
+ returnValue = source;
+ } else {
+ returnValue = Dart_LoadScript(resolved_script_uri, source, 0, 0);
}
- return Dart_LoadScript(resolved_script_uri, source, 0, 0);
}
+ free(const_cast<uint8_t *>(buffer));
+ return returnValue;
}
« 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