Linux: Fix crash due to Chromium modifying the |argv| passed to main() (issue #620).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1750 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
3a70815036
commit
133317eeec
|
@ -6,6 +6,10 @@
|
|||
#define CEF_TESTS_CEFCLIENT_UTIL_H_
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "include/cef_task.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
@ -34,4 +38,28 @@
|
|||
#define REQUIRE_IO_THREAD() ASSERT(CefCurrentlyOn(TID_IO));
|
||||
#define REQUIRE_FILE_THREAD() ASSERT(CefCurrentlyOn(TID_FILE));
|
||||
|
||||
// Helper class to manage a scoped copy of |argv|.
|
||||
class ScopedArgArray {
|
||||
public:
|
||||
ScopedArgArray(int argc, char* argv[]) {
|
||||
array_ = new char*[argc];
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
values_.push_back(argv[i]);
|
||||
array_[i] = const_cast<char*>(values_[i].c_str());
|
||||
}
|
||||
}
|
||||
~ScopedArgArray() {
|
||||
delete [] array_;
|
||||
}
|
||||
|
||||
char** array() const { return array_; }
|
||||
|
||||
private:
|
||||
char** array_;
|
||||
|
||||
// Keep values in a vector separate from |array_| because various users may
|
||||
// modify |array_| and we still want to clean up memory properly.
|
||||
std::vector<std::string> values_;
|
||||
};
|
||||
|
||||
#endif // CEF_TESTS_CEFCLIENT_UTIL_H_
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "include/cef_app.h"
|
||||
#include "include/cef_task.h"
|
||||
#include "tests/cefclient/client_app.h"
|
||||
#include "tests/cefclient/util.h"
|
||||
#include "tests/unittests/test_handler.h"
|
||||
#include "tests/unittests/test_suite.h"
|
||||
#include "base/bind.h"
|
||||
|
@ -58,6 +59,15 @@ void RunTests(CefTestThread* thread) {
|
|||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
#if defined(OS_LINUX)
|
||||
// Create a copy of |argv| on Linux because Chromium mangles the value
|
||||
// internally (see issue #620).
|
||||
ScopedArgArray scoped_arg_array(argc, argv);
|
||||
char** argv_copy = scoped_arg_array.array();
|
||||
#else
|
||||
char** argv_copy = argv;
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN)
|
||||
CefMainArgs main_args(::GetModuleHandle(NULL));
|
||||
#else
|
||||
|
@ -80,7 +90,7 @@ int main(int argc, char* argv[]) {
|
|||
return exit_code;
|
||||
|
||||
// Initialize the CommandLine object.
|
||||
CefTestSuite::InitCommandLine(argc, argv);
|
||||
CefTestSuite::InitCommandLine(argc, argv_copy);
|
||||
|
||||
CefSettings settings;
|
||||
CefTestSuite::GetSettings(settings);
|
||||
|
@ -94,8 +104,8 @@ int main(int argc, char* argv[]) {
|
|||
// Initialize CEF.
|
||||
CefInitialize(main_args, settings, app, windows_sandbox_info);
|
||||
|
||||
// Create the test suite object.
|
||||
CefTestSuite test_suite(argc, argv);
|
||||
// Create the test suite object. TestSuite will modify |argv_copy|.
|
||||
CefTestSuite test_suite(argc, argv_copy);
|
||||
|
||||
int retval;
|
||||
|
||||
|
@ -133,4 +143,4 @@ int main(int argc, char* argv[]) {
|
|||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue