netipmid: use shared_ptr on messages instead of unique_ptr+references
Messages were being created and held by unique_ptr objects and then
shared via reference. This is dangerous and sidesteps the whole point of
a unique_ptr, which is to enforce single ownership. This replaces the
usage with a shared_ptr, which denotes shared ownership.
Change-Id: I19ed2693f5a0f5ce47d720ed255fa05bdf3844f8
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/sd_event_loop.cpp b/sd_event_loop.cpp
index a5fd41d..aa5224a 100644
--- a/sd_event_loop.cpp
+++ b/sd_event_loop.cpp
@@ -29,24 +29,22 @@
// Initialize the Message Handler with the socket channel
message::Handler msgHandler(channelPtr);
- std::unique_ptr<message::Message> inMessage;
-
// Read the incoming IPMI packet
- inMessage = msgHandler.receive();
+ std::shared_ptr<message::Message> inMessage(msgHandler.receive());
if (inMessage == nullptr)
{
return 0;
}
// Execute the Command
- auto outMessage = msgHandler.executeCommand(*(inMessage.get()));
+ auto outMessage = msgHandler.executeCommand(inMessage);
if (outMessage == nullptr)
{
return 0;
}
// Send the response IPMI Message
- msgHandler.send(*(outMessage.get()));
+ msgHandler.send(outMessage);
}
catch (std::exception& e)
{