diff --git a/src/node.cc b/src/node.cc index c5be22a725..4d21f97111 100644 --- a/src/node.cc +++ b/src/node.cc @@ -207,7 +207,7 @@ bool config_preserve_symlinks = false; bool config_expose_internals = false; // Set in node.cc by ParseArgs when --redirect-warnings= is used. -const char* config_warning_file; +std::string config_warning_file; // NOLINT(runtime/string) // process-relative uptime base, initialized at start-up static double prog_start_time; @@ -4410,9 +4410,8 @@ void Init(int* argc, if (openssl_config.empty()) SafeGetenv("OPENSSL_CONF", &openssl_config); - if (auto redirect_warnings = secure_getenv("NODE_REDIRECT_WARNINGS")) { - config_warning_file = redirect_warnings; - } + if (config_warning_file.empty()) + SafeGetenv("NODE_REDIRECT_WARNINGS", &config_warning_file); // Parse a few arguments which are specific to Node. int v8_argc; diff --git a/src/node_config.cc b/src/node_config.cc index c80e3f640d..0e61847096 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -49,11 +49,12 @@ void InitConfig(Local target, if (config_expose_internals) READONLY_BOOLEAN_PROPERTY("exposeInternals"); - if (config_warning_file != nullptr) { + if (!config_warning_file.empty()) { Local name = OneByteString(env->isolate(), "warningFile"); Local value = String::NewFromUtf8(env->isolate(), - config_warning_file, - v8::NewStringType::kNormal) + config_warning_file.data(), + v8::NewStringType::kNormal, + config_warning_file.size()) .ToLocalChecked(); target->DefineOwnProperty(env->context(), name, value).FromJust(); } diff --git a/src/node_internals.h b/src/node_internals.h index 642e61c2c2..adcb7f835a 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -52,7 +52,7 @@ extern bool config_expose_internals; // Set in node.cc by ParseArgs when --redirect-warnings= is used. // Used to redirect warning output to a file rather than sending // it to stderr. -extern const char* config_warning_file; +extern std::string config_warning_file; // Forward declaration class Environment;