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 <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax authored and MylesBorins committed Dec 26, 2018
1 parent add566e commit b801b03
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 b801b03

Please sign in to comment.