diff options
author | Vernon Mauery <vernon.mauery@linux.intel.com> | 2018-10-25 08:52:23 -0700 |
---|---|---|
committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2018-11-21 10:51:29 -0800 |
commit | 224f36a4e5b10ac3f84958307a61687cc041d064 (patch) | |
tree | 94c9d0a02fd24c46774e218cd92e16a5756d8497 | |
parent | d999ffc12211f5d5c6cd2196dd525e69e2fc0f58 (diff) | |
download | phosphor-net-ipmid-224f36a4e5b10ac3f84958307a61687cc041d064.tar.gz phosphor-net-ipmid-224f36a4e5b10ac3f84958307a61687cc041d064.zip |
netipmid: use shared_ptr on session instead of shared_ptr+references
session objects were being created and held by shared_ptr objects and
then shared via reference. This is dangerous and sidesteps the whole
point of a shared_ptr, which is to share reference-counted ownership.
This replaces the usage with a shared_ptr, which shows shared ownership.
Change-Id: Ie22d812a6d260d606201eca6a9011e773c89e487
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
-rw-r--r-- | message_handler.cpp | 2 | ||||
-rw-r--r-- | message_parsers.cpp | 12 | ||||
-rw-r--r-- | message_parsers.hpp | 10 |
3 files changed, 14 insertions, 10 deletions
diff --git a/message_handler.cpp b/message_handler.cpp index b9cc6ab..68c1b60 100644 --- a/message_handler.cpp +++ b/message_handler.cpp @@ -168,7 +168,7 @@ void Handler::send(std::shared_ptr<Message> outMessage) std::get<session::Manager&>(singletonPool).getSession(sessionID); // Flatten the packet - auto packet = parser::flatten(outMessage, sessionHeader, *session); + auto packet = parser::flatten(outMessage, sessionHeader, session); // Write the packet auto writeStatus = channel->write(packet); diff --git a/message_parsers.cpp b/message_parsers.cpp index ddb9d01..d7074fa 100644 --- a/message_parsers.cpp +++ b/message_parsers.cpp @@ -55,7 +55,8 @@ std::tuple<std::shared_ptr<Message>, SessionHeader> } std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage, - SessionHeader authType, session::Session& session) + SessionHeader authType, + std::shared_ptr<session::Session> session) { // Call the flatten routine based on the header type switch (authType) @@ -108,7 +109,7 @@ std::shared_ptr<Message> unflatten(std::vector<uint8_t>& inPacket) } std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage, - session::Session& session) + std::shared_ptr<session::Session> session) { std::vector<uint8_t> packet(sizeof(SessionHeader_t)); @@ -191,7 +192,7 @@ std::shared_ptr<Message> unflatten(std::vector<uint8_t>& inPacket) } std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage, - session::Session& session) + std::shared_ptr<session::Session> session) { std::vector<uint8_t> packet(sizeof(SessionHeader_t)); @@ -243,7 +244,8 @@ std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage, namespace internal { -void addSequenceNumber(std::vector<uint8_t>& packet, session::Session& session) +void addSequenceNumber(std::vector<uint8_t>& packet, + std::shared_ptr<session::Session> session) { SessionHeader_t* header = reinterpret_cast<SessionHeader_t*>(packet.data()); @@ -253,7 +255,7 @@ void addSequenceNumber(std::vector<uint8_t>& packet, session::Session& session) } else { - auto seqNum = session.sequenceNums.increment(); + auto seqNum = session->sequenceNums.increment(); header->sessSeqNum = endian::to_ipmi(seqNum); } } diff --git a/message_parsers.hpp b/message_parsers.hpp index b38da40..489eb23 100644 --- a/message_parsers.hpp +++ b/message_parsers.hpp @@ -73,7 +73,8 @@ std::tuple<std::shared_ptr<Message>, SessionHeader> * @return IPMI packet on success */ std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage, - SessionHeader authType, session::Session& session); + SessionHeader authType, + std::shared_ptr<session::Session> session); } // namespace parser @@ -112,7 +113,7 @@ std::shared_ptr<Message> unflatten(std::vector<uint8_t>& inPacket); * @return IPMI packet on success */ std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage, - session::Session& session); + std::shared_ptr<session::Session> session); } // namespace ipmi15parser @@ -159,7 +160,7 @@ std::shared_ptr<Message> unflatten(std::vector<uint8_t>& inPacket); * @return IPMI packet on success */ std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage, - session::Session& session); + std::shared_ptr<session::Session> session); namespace internal { @@ -171,7 +172,8 @@ namespace internal * @param[in] session - session handle * */ -void addSequenceNumber(std::vector<uint8_t>& packet, session::Session& session); +void addSequenceNumber(std::vector<uint8_t>& packet, + std::shared_ptr<session::Session> session); /** * @brief Verify the integrity data of the incoming IPMI packet |