LibCore: Ensure exec() keeps a reference to the executable path

When called with `SearchInPath::Yes`, calls to `Core::System::exec()`
would fail. The value returned from
`resolve_executable_from_environment()` was assigned to a StringView,
but the original reference was not kept, causing the StringView to
appear empty.
This commit is contained in:
Tim Ledbetter 2023-06-07 18:12:00 +01:00 committed by Jelle Raaijmakers
parent 0177e4e6ba
commit cbe5aeb917
Notes: sideshowbarker 2024-07-17 03:03:44 +09:00

View file

@ -1263,14 +1263,15 @@ ErrorOr<void> exec(StringView filename, ReadonlySpan<StringView> arguments, Sear
};
StringView exec_filename;
String resolved_executable_path;
if (search_in_path == SearchInPath::Yes) {
auto executable_or_error = resolve_executable_from_environment(filename);
if (executable_or_error.is_error())
return executable_or_error.release_error();
exec_filename = executable_or_error.value();
resolved_executable_path = executable_or_error.release_value();
exec_filename = resolved_executable_path;
} else {
exec_filename = filename;
}