Capture weak reference of sensor object in lambda
dbus callback methods are capturing 'this' pointer directly. A sensor
object can get deleted while a callback is pending invocation. This is
crashing ipmbsensor daemon.
Capture weak reference in place of this pointer.
Tested: Run ipmbsensor as a binary with entity manager constantly
restarting to simulated destruction and construction of new sensor
object. No crash was observed after running for three hours. Prior to
this ipmbsensor was crashing within one hour
Signed-off-by: Vikash Chandola <vikash.chandola@intel.com>
Change-Id: Idd53cbeb912c87ca3c4c09302279fc9383c569bc
diff --git a/include/IpmbSensor.hpp b/include/IpmbSensor.hpp
index f142a5a..6467b57 100644
--- a/include/IpmbSensor.hpp
+++ b/include/IpmbSensor.hpp
@@ -75,7 +75,12 @@
} // namespace me_bridge
} // namespace ipmi
-struct IpmbSensor : public Sensor
+using IpmbMethodType =
+ std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>;
+
+struct IpmbSensor :
+ public Sensor,
+ public std::enable_shared_from_this<IpmbSensor>
{
IpmbSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_service& io, const std::string& name,
@@ -115,6 +120,9 @@
ReadingFormat readingFormat = ReadingFormat::byte0;
private:
+ void sendIpmbRequest(void);
sdbusplus::asio::object_server& objectServer;
boost::asio::steady_timer waitTimer;
+ void ipmbRequestCompletionCb(const boost::system::error_code& ec,
+ const IpmbMethodType& response);
};