From 7c85c33666dad5bb55eb642a57beb87ee92cb873 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 8 Sep 2024 10:36:00 -0700 Subject: [PATCH] [ntcore] Avoid duplicate addition of publishers in server (#7052) We emitted a warning but went on to do unsafe things. This could cause a delayed crash. --- ntcore/src/main/native/cpp/net/ServerImpl.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ntcore/src/main/native/cpp/net/ServerImpl.cpp b/ntcore/src/main/native/cpp/net/ServerImpl.cpp index 832cff0986..4dbb3e82a2 100644 --- a/ntcore/src/main/native/cpp/net/ServerImpl.cpp +++ b/ntcore/src/main/native/cpp/net/ServerImpl.cpp @@ -211,14 +211,14 @@ void ServerImpl::ClientData4Base::ClientPublish(int64_t pubuid, pubuid, std::make_unique(this, topic, pubuid)); if (!isNew) { WARN("client {} duplicate publish of pubuid {}", m_id, pubuid); + } else { + // add publisher to topic + topic->AddPublisher(this, publisherIt->getSecond().get()); + + // update meta data + m_server.UpdateMetaTopicPub(topic); } - // add publisher to topic - topic->AddPublisher(this, publisherIt->getSecond().get()); - - // update meta data - m_server.UpdateMetaTopicPub(topic); - // respond with announce with pubuid to client DEBUG4("client {}: announce {} pubuid {}", m_id, topic->name, pubuid); SendAnnounce(topic, pubuid);