mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe
This commit is contained in:
parent
3a9f00c59b
commit
97e97bccab
105 changed files with 629 additions and 290 deletions
|
@ -231,13 +231,17 @@ protected:
|
|||
// Sometimes we might receive a partial message. That's okay, just stash away
|
||||
// the unprocessed bytes and we'll prepend them to the next incoming message
|
||||
// in the next run of this function.
|
||||
auto remaining_bytes = ByteBuffer::copy(bytes.data() + index, bytes.size() - index);
|
||||
auto remaining_bytes_result = ByteBuffer::copy(bytes.span().slice(index));
|
||||
if (!remaining_bytes_result.has_value()) {
|
||||
dbgln("{}::drain_messages_from_peer: Failed to allocate buffer", *this);
|
||||
return false;
|
||||
}
|
||||
if (!m_unprocessed_bytes.is_empty()) {
|
||||
dbgln("{}::drain_messages_from_peer: Already have unprocessed bytes", *this);
|
||||
shutdown();
|
||||
return false;
|
||||
}
|
||||
m_unprocessed_bytes = remaining_bytes;
|
||||
m_unprocessed_bytes = remaining_bytes_result.release_value();
|
||||
}
|
||||
|
||||
if (!m_unprocessed_messages.is_empty()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue