summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/command_line.cc8
-rw-r--r--base/command_line_unittest.cc8
2 files changed, 15 insertions, 1 deletions
diff --git a/base/command_line.cc b/base/command_line.cc
index b3a79eb..acf2502 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -168,7 +168,13 @@ CommandLine::~CommandLine() {
// static
void CommandLine::Init(int argc, const char* const* argv) {
- delete current_process_commandline_;
+ if (current_process_commandline_) {
+ // If this is intentional, Reset() must be called first. If we are using
+ // the shared build mode, we have to share a single object across multiple
+ // shared libraries.
+ return;
+ }
+
current_process_commandline_ = new CommandLine(NO_PROGRAM);
#if defined(OS_WIN)
current_process_commandline_->ParseFromString(::GetCommandLineW());
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index a8d1eed..c2bfd11 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -284,3 +284,11 @@ TEST(CommandLineTest, ProgramQuotes) {
EXPECT_EQ('"', cmd_string[program_string.length() + 1]);
}
#endif
+
+// Calling Init multiple times should not modify the previous CommandLine.
+TEST(CommandLineTest, Init) {
+ CommandLine* initial = CommandLine::ForCurrentProcess();
+ CommandLine::Init(0, NULL);
+ CommandLine* current = CommandLine::ForCurrentProcess();
+ EXPECT_EQ(initial, current);
+}