mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +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
2 changed files with 12 additions and 3 deletions
|
@ -288,7 +288,7 @@ pid_t Process::sys$fork(RegisterDump& regs)
|
||||||
return child->pid();
|
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('/');
|
auto parts = path.split('/');
|
||||||
if (parts.isEmpty())
|
if (parts.isEmpty())
|
||||||
|
@ -309,7 +309,6 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>
|
||||||
return -ENOTIMPL;
|
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);
|
auto vmo = VMObject::create_file_backed(descriptor->vnode(), descriptor->metadata().size);
|
||||||
vmo->set_name(descriptor->absolute_path());
|
vmo->set_name(descriptor->absolute_path());
|
||||||
auto* region = allocate_region_with_vmo(LinearAddress(), descriptor->metadata().size, vmo.copyRef(), 0, "helper", true, false);
|
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
|
#endif
|
||||||
|
|
||||||
set_state(Skip1SchedulerPass);
|
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) {
|
if (current == this) {
|
||||||
Scheduler::yield();
|
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);
|
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);
|
void push_value_on_stack(dword);
|
||||||
|
|
||||||
PageDirectory* m_page_directory { nullptr };
|
PageDirectory* m_page_directory { nullptr };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue