1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:48:12 +00:00

Kernel: Fix SharedBuffer reference counting on fork

We need to not only add a record for a reference, but we need
to copy the reference count on fork as well, because the code
in the fork assumes that it has the same amount of references,
still.

Also, once all references are dropped when a process is disowned,
delete the shared buffer.

Fixes #4076
This commit is contained in:
Tom 2020-11-24 10:26:32 -07:00 committed by Andreas Kling
parent 018eff802b
commit 68abd1cb29
3 changed files with 22 additions and 9 deletions

View file

@ -37,8 +37,12 @@ void Process::disown_all_shared_buffers()
Vector<SharedBuffer*, 32> buffers_to_disown;
for (auto& it : shared_buffers().resource())
buffers_to_disown.append(it.value.ptr());
for (auto* shared_buffer : buffers_to_disown)
shared_buffer->disown(m_pid);
for (auto* shared_buffer : buffers_to_disown) {
if (shared_buffer->disown(m_pid)) {
shared_buffers().resource().remove(shared_buffer->id());
delete shared_buffer;
}
}
}
int Process::sys$shbuf_create(int size, void** buffer)