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

Unified 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: 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 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/main.cc
diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc
index a90c1a45cd78f32f45495a9c3ab5c02926505817..b25f3006be59384a10622fb93b35943171670348 100644
--- a/runtime/bin/main.cc
+++ b/runtime/bin/main.cc
@@ -282,29 +282,35 @@ static bool ProcessEnvironmentOption(const char* arg,
environment = new HashMap(&HashMap::SameStringValue, 4);
}
// Split the name=value part of the -Dname=value argument.
- char* name;
- char* value = NULL;
const char* equals_pos = strchr(arg, '=');
if (equals_pos == NULL) {
// No equal sign (name without value) currently not supported.
Log::PrintErr("No value given to -D option\n");
return false;
- } else {
- int name_len = equals_pos - arg;
- if (name_len == 0) {
- Log::PrintErr("No name given to -D option\n");
- return false;
- }
- // Split name=value into name and value.
- name = reinterpret_cast<char*>(malloc(name_len + 1));
- strncpy(name, arg, name_len);
- name[name_len] = '\0';
- value = strdup(equals_pos + 1);
}
+
+ char* name;
+ char* value = NULL;
+ int name_len = equals_pos - arg;
+ if (name_len == 0) {
+ Log::PrintErr("No name given to -D option\n");
+ return false;
+ }
+ // Split name=value into name and value.
+ name = reinterpret_cast<char*>(malloc(name_len + 1));
+ strncpy(name, arg, name_len);
+ name[name_len] = '\0';
+ value = strdup(equals_pos + 1);
HashMap::Entry* entry = environment->Lookup(
GetHashmapKeyFromString(name), HashMap::StringHash(name), true);
ASSERT(entry != NULL); // Lookup adds an entry if key not found.
- entry->value = value;
+ if (entry->value == NULL) {
+ entry->value = value;
+ } else {
+ free(name);
+ free(entry->value);
+ entry->value = value;
+ }
siva 2016/08/08 19:41:05 how about if (entry->value != NULL) { free(name
zra 2016/08/08 19:53:13 Done.
return true;
}
« 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