浏览代码

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.
Tim Ledbetter 2 年之前
父节点
当前提交
cbe5aeb917
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      Userland/Libraries/LibCore/System.cpp

+ 3 - 2
Userland/Libraries/LibCore/System.cpp

@@ -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;
     }