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

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

Issue 2222013002: Fixes leak of duplicate command line environment strings (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comment Created 4 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
« 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 ASSERT(arg != NULL); 275 ASSERT(arg != NULL);
276 if (*arg == '\0') { 276 if (*arg == '\0') {
277 // Ignore empty -D option. 277 // Ignore empty -D option.
278 Log::PrintErr("No arguments given to -D option\n"); 278 Log::PrintErr("No arguments given to -D option\n");
279 return true; 279 return true;
280 } 280 }
281 if (environment == NULL) { 281 if (environment == NULL) {
282 environment = new HashMap(&HashMap::SameStringValue, 4); 282 environment = new HashMap(&HashMap::SameStringValue, 4);
283 } 283 }
284 // Split the name=value part of the -Dname=value argument. 284 // Split the name=value part of the -Dname=value argument.
285 char* name;
286 char* value = NULL;
287 const char* equals_pos = strchr(arg, '='); 285 const char* equals_pos = strchr(arg, '=');
288 if (equals_pos == NULL) { 286 if (equals_pos == NULL) {
289 // No equal sign (name without value) currently not supported. 287 // No equal sign (name without value) currently not supported.
290 Log::PrintErr("No value given to -D option\n"); 288 Log::PrintErr("No value given to -D option\n");
291 return false; 289 return false;
292 } else {
293 int name_len = equals_pos - arg;
294 if (name_len == 0) {
295 Log::PrintErr("No name given to -D option\n");
296 return false;
297 }
298 // Split name=value into name and value.
299 name = reinterpret_cast<char*>(malloc(name_len + 1));
300 strncpy(name, arg, name_len);
301 name[name_len] = '\0';
302 value = strdup(equals_pos + 1);
303 } 290 }
291
292 char* name;
293 char* value = NULL;
294 int name_len = equals_pos - arg;
295 if (name_len == 0) {
296 Log::PrintErr("No name given to -D option\n");
297 return false;
298 }
299 // Split name=value into name and value.
300 name = reinterpret_cast<char*>(malloc(name_len + 1));
301 strncpy(name, arg, name_len);
302 name[name_len] = '\0';
303 value = strdup(equals_pos + 1);
304 HashMap::Entry* entry = environment->Lookup( 304 HashMap::Entry* entry = environment->Lookup(
305 GetHashmapKeyFromString(name), HashMap::StringHash(name), true); 305 GetHashmapKeyFromString(name), HashMap::StringHash(name), true);
306 ASSERT(entry != NULL); // Lookup adds an entry if key not found. 306 ASSERT(entry != NULL); // Lookup adds an entry if key not found.
307 if (entry->value != NULL) {
308 free(name);
309 free(entry->value);
310 }
307 entry->value = value; 311 entry->value = value;
308 return true; 312 return true;
309 } 313 }
310 314
311 315
312 static bool ProcessCompileAllOption(const char* arg, 316 static bool ProcessCompileAllOption(const char* arg,
313 CommandLineOptions* vm_options) { 317 CommandLineOptions* vm_options) {
314 ASSERT(arg != NULL); 318 ASSERT(arg != NULL);
315 if (*arg != '\0') { 319 if (*arg != '\0') {
316 return false; 320 return false;
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 Platform::Exit(Process::GlobalExitCode()); 1791 Platform::Exit(Process::GlobalExitCode());
1788 } 1792 }
1789 1793
1790 } // namespace bin 1794 } // namespace bin
1791 } // namespace dart 1795 } // namespace dart
1792 1796
1793 int main(int argc, char** argv) { 1797 int main(int argc, char** argv) {
1794 dart::bin::main(argc, argv); 1798 dart::bin::main(argc, argv);
1795 UNREACHABLE(); 1799 UNREACHABLE();
1796 } 1800 }
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