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

Unified Diff: runtime/bin/extensions.cc

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 | « runtime/bin/extensions.h ('k') | runtime/bin/extensions_android.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/extensions.cc
diff --git a/runtime/bin/extensions.cc b/runtime/bin/extensions.cc
index eaed7bb38b1a2775e30c4563bab40295d2888a53..7fa06fd64524cbeed4cff47b0c2f58b7ec3d1a4a 100644
--- a/runtime/bin/extensions.cc
+++ b/runtime/bin/extensions.cc
@@ -6,12 +6,11 @@
#include <stdio.h>
+#include "bin/dartutils.h"
+#include "bin/file.h"
#include "include/dart_api.h"
#include "platform/assert.h"
#include "platform/globals.h"
-#include "bin/dartutils.h"
-#include "bin/file.h"
-
namespace dart {
namespace bin {
@@ -25,17 +24,15 @@ Dart_Handle Extensions::LoadExtension(const char* extension_directory,
return Dart_NewApiError("Cannot load native extensions over http:");
}
const char* library_strings[] = { extension_directory, extension_file, NULL };
- char* library_file = Concatenate(library_strings);
+ const char* library_file = Concatenate(library_strings);
void* library_handle = LoadExtensionLibrary(library_file);
- free(library_file);
if (library_handle == NULL) {
return GetError();
}
const char* strings[] = { extension_name, "_Init", NULL };
- char* init_function_name = Concatenate(strings);
+ const char* init_function_name = Concatenate(strings);
void* init_function = ResolveSymbol(library_handle, init_function_name);
- free(init_function_name);
Dart_Handle result = GetError();
if (Dart_IsError(result)) {
return result;
@@ -48,13 +45,13 @@ Dart_Handle Extensions::LoadExtension(const char* extension_directory,
// Concatenates a NULL terminated array of strings.
-// The returned string must be freed.
-char* Extensions::Concatenate(const char** strings) {
+// The returned string is scope allocated.
+const char* Extensions::Concatenate(const char** strings) {
int size = 1; // null termination.
for (int i = 0; strings[i] != NULL; i++) {
size += strlen(strings[i]);
}
- char* result = reinterpret_cast<char*>(malloc(size));
+ char* result = reinterpret_cast<char*>(Dart_ScopeAllocate(size));
int index = 0;
for (int i = 0; strings[i] != NULL; i++) {
index += snprintf(result + index, size - index, "%s", strings[i]);
« no previous file with comments | « runtime/bin/extensions.h ('k') | runtime/bin/extensions_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698