Permalink
Browse files

src: use std::vector for setting up process.execPath

Use `std::vector` as an RAII-style alternative to allocating
and deleting raw memory storage.

PR-URL: #25069
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
addaleax authored and MylesBorins committed Dec 15, 2018
1 parent add566e commit b801b0372a924a60f97fbd58a2a318f7d56f3fd1
Showing with 16 additions and 15 deletions.
  1. +16 −15 src/node.cc
@@ -1150,22 +1150,23 @@ void SetupProcessObject(Environment* env,
SECURITY_REVERSIONS(V)
#undef V

size_t exec_path_len = 2 * PATH_MAX;
char* exec_path = new char[exec_path_len];
Local<String> exec_path_value;
if (uv_exepath(exec_path, &exec_path_len) == 0) {
exec_path_value = String::NewFromUtf8(env->isolate(),
exec_path,
NewStringType::kInternalized,
exec_path_len).ToLocalChecked();
} else {
exec_path_value = String::NewFromUtf8(env->isolate(), args[0].c_str(),
NewStringType::kInternalized).ToLocalChecked();
{
size_t exec_path_len = 2 * PATH_MAX;
std::vector<char> exec_path(exec_path_len);
Local<String> exec_path_value;
if (uv_exepath(exec_path.data(), &exec_path_len) == 0) {
exec_path_value = String::NewFromUtf8(env->isolate(),
exec_path.data(),
NewStringType::kInternalized,
exec_path_len).ToLocalChecked();
} else {
exec_path_value = String::NewFromUtf8(env->isolate(), args[0].c_str(),
NewStringType::kInternalized).ToLocalChecked();
}
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
exec_path_value).FromJust();
}
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
exec_path_value).FromJust();
delete[] exec_path;

auto debug_port_string = FIXED_ONE_BYTE_STRING(env->isolate(), "debugPort");
CHECK(process->SetAccessor(env->context(),

0 comments on commit b801b03

Please sign in to comment.