mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
Okay, now *actually* plug the leaks in exec().
I didn't even put the { } properly around everything that would leak. Let's make sure this works correctly by splitting out the work into a helper called do_exec().
This commit is contained in:
parent
e0ca6bb97e
commit
985074c790
Notes:
sideshowbarker
2024-07-19 16:11:51 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/985074c790e
2 changed files with 12 additions and 3 deletions
|
@ -288,7 +288,7 @@ pid_t Process::sys$fork(RegisterDump& regs)
|
|||
return child->pid();
|
||||
}
|
||||
|
||||
int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>&& environment)
|
||||
int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<String>&& environment)
|
||||
{
|
||||
auto parts = path.split('/');
|
||||
if (parts.isEmpty())
|
||||
|
@ -309,7 +309,6 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>
|
|||
return -ENOTIMPL;
|
||||
}
|
||||
|
||||
{ // Put everything into a scope so things get cleaned up before we yield-teleport into the new executable.
|
||||
auto vmo = VMObject::create_file_backed(descriptor->vnode(), descriptor->metadata().size);
|
||||
vmo->set_name(descriptor->absolute_path());
|
||||
auto* region = allocate_region_with_vmo(LinearAddress(), descriptor->metadata().size, vmo.copyRef(), 0, "helper", true, false);
|
||||
|
@ -403,7 +402,16 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>
|
|||
#endif
|
||||
|
||||
set_state(Skip1SchedulerPass);
|
||||
} // Ready to yield-teleport!
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>&& environment)
|
||||
{
|
||||
// The bulk of exec() is done by do_exec(), which ensures that all locals
|
||||
// are cleaned up by the time we yield-teleport below.
|
||||
int rc = do_exec(path, move(arguments), move(environment));
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
if (current == this) {
|
||||
Scheduler::yield();
|
||||
|
|
|
@ -209,6 +209,7 @@ private:
|
|||
|
||||
Process(String&& name, uid_t, gid_t, pid_t ppid, RingLevel, RetainPtr<VirtualFileSystem::Node>&& cwd = nullptr, RetainPtr<VirtualFileSystem::Node>&& executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
|
||||
|
||||
int do_exec(const String& path, Vector<String>&& arguments, Vector<String>&& environment);
|
||||
void push_value_on_stack(dword);
|
||||
|
||||
PageDirectory* m_page_directory { nullptr };
|
||||
|
|
Loading…
Add table
Reference in a new issue