Skip to content

Commit

Permalink
src: use std::vector for setting up process.execPath
Browse files Browse the repository at this point in the history
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 25, 2018
1 parent 1a562cc commit 3dcdfe3
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 3dcdfe3

Please sign in to comment.