From 25db315b2948595f2e4a0bf266596ddba84f05e4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 8 May 2020 21:40:06 +0200 Subject: [PATCH] LibIPC: Use NonnullOwnPtrVector in IPC::ServerConnection We never want to store null messages, so make it impossible to do so. --- Libraries/LibIPC/ServerConnection.h | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Libraries/LibIPC/ServerConnection.h b/Libraries/LibIPC/ServerConnection.h index d9dad2b7fbb..9f9b6da9182 100644 --- a/Libraries/LibIPC/ServerConnection.h +++ b/Libraries/LibIPC/ServerConnection.h @@ -84,11 +84,8 @@ public: // Double check we don't already have the event waiting for us. // Otherwise we might end up blocked for a while for no reason. for (size_t i = 0; i < m_unprocessed_messages.size(); ++i) { - if (m_unprocessed_messages[i]->message_id() == MessageType::static_message_id()) { - auto message = move(m_unprocessed_messages[i]); - m_unprocessed_messages.remove(i); - return message.template release_nonnull(); - } + if (m_unprocessed_messages[i].message_id() == MessageType::static_message_id()) + return m_unprocessed_messages.take(i).template release_nonnull(); } for (;;) { fd_set rfds; @@ -103,11 +100,8 @@ public: if (!drain_messages_from_server()) return nullptr; for (size_t i = 0; i < m_unprocessed_messages.size(); ++i) { - if (m_unprocessed_messages[i]->message_id() == MessageType::static_message_id()) { - auto message = move(m_unprocessed_messages[i]); - m_unprocessed_messages.remove(i); - return message.template release_nonnull(); - } + if (m_unprocessed_messages[i].message_id() == MessageType::static_message_id()) + return m_unprocessed_messages.take(i).template release_nonnull(); } } } @@ -162,9 +156,9 @@ private: for (size_t index = 0; index < bytes.size(); index += decoded_bytes) { auto remaining_bytes = ByteBuffer::wrap(bytes.data() + index, bytes.size() - index); if (auto message = LocalEndpoint::decode_message(remaining_bytes, decoded_bytes)) { - m_unprocessed_messages.append(move(message)); + m_unprocessed_messages.append(message.release_nonnull()); } else if (auto message = PeerEndpoint::decode_message(remaining_bytes, decoded_bytes)) { - m_unprocessed_messages.append(move(message)); + m_unprocessed_messages.append(message.release_nonnull()); } else { ASSERT_NOT_REACHED(); } @@ -183,15 +177,15 @@ private: { auto messages = move(m_unprocessed_messages); for (auto& message : messages) { - if (message->endpoint_magic() == LocalEndpoint::static_magic()) - m_local_endpoint.handle(*message); + if (message.endpoint_magic() == LocalEndpoint::static_magic()) + m_local_endpoint.handle(message); } } LocalEndpoint& m_local_endpoint; RefPtr m_connection; RefPtr m_notifier; - Vector> m_unprocessed_messages; + NonnullOwnPtrVector m_unprocessed_messages; int m_server_pid { -1 }; int m_my_client_id { -1 }; };