Fix softoff crash due to double free corruption
In its present condition, the instance database gets initialized
within the hostSoftOff function. Consequently, once the function
execution is complete, the database goes out of scope, triggering
the invocation of the instanceDb destructor. This, in turn,
prematurely destroys the instance database in the middle of the
softpoweroff flow, resulting in a double free corruption.
Tested:
After implementing the fix, softoff was tested to ensure it does
not crash.
Change-Id: I251201b06864a8a5273bfaa23468a06ad678763a
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/softoff/softoff.hpp b/softoff/softoff.hpp
index 2bf3968..edec74e 100644
--- a/softoff/softoff.hpp
+++ b/softoff/softoff.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "common/instance_id.hpp"
#include "common/transport.hpp"
#include "common/types.hpp"
@@ -22,8 +23,10 @@
*
* @param[in] bus - system D-Bus handler
* @param[in] event - sd_event handler
+ * @param[in] instanceDb - pldm instance database
*/
- SoftPowerOff(sdbusplus::bus_t& bus, sd_event* event);
+ SoftPowerOff(sdbusplus::bus_t& bus, sd_event* event,
+ InstanceIdDb& instanceIdDb);
/** @brief Is the pldm-softpoweroff has error.
* if hasError is true, that means the pldm-softpoweroff failed to
@@ -142,6 +145,10 @@
* to BMC's pldmd, and the pldmd will emit the StateSensorEvent signal.
**/
std::unique_ptr<sdbusplus::bus::match_t> pldmEventSignal;
+
+ /** @brief Reference to the instance database
+ */
+ InstanceIdDb& instanceIdDb;
};
} // namespace pldm