Fix pldm crashes
This commit attempts to fix three PLDM crashes
1. Capturing handler using a reference in dbus match handling
lambda function.
dbus matches are aync,so by the time we get a dbus match we would
have exited the function in which the dbus match lambda is defined
so the handler would be nullptr , and dereferencing them would lead
to a segmentation fault.
2. We cannot be deleting elements of a container while iterating over
the same container.
Reference : https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: I54cb03ccf61c4fa50fbf7fb34f7b014d0247ea7b
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 63512a3..f23407b 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -88,14 +88,10 @@
if (propVal == "xyz.openbmc_project.State.Host.HostState.Off")
{
// Delete all the remote terminus information
- for (const auto& terminusInfo : this->tlPDRInfo)
- {
- if (terminusInfo.first != TERMINUS_HANDLE)
- {
- this->tlPDRInfo.erase(terminusInfo.first);
- }
- }
-
+ std::erase_if(tlPDRInfo, [](const auto& item) {
+ auto const& [key, value] = item;
+ return key != TERMINUS_HANDLE;
+ });
pldm_pdr_remove_remote_pdrs(repo);
pldm_entity_association_tree_destroy_root(entityTree);
pldm_entity_association_tree_copy_root(bmcEntityTree,
diff --git a/oem/ibm/libpldmresponder/file_io.hpp b/oem/ibm/libpldmresponder/file_io.hpp
index 10c6d47..ee8074d 100644
--- a/oem/ibm/libpldmresponder/file_io.hpp
+++ b/oem/ibm/libpldmresponder/file_io.hpp
@@ -234,7 +234,7 @@
sdbusplus::bus::match::rules::interfacesAdded() +
sdbusplus::bus::match::rules::argNpath(0, dumpObjPath),
[this, hostSockFd, hostEid, dbusImplReqester,
- &handler](sdbusplus::message::message& msg) {
+ handler](sdbusplus::message::message& msg) {
std::map<
std::string,
std::map<std::string, std::variant<std::string, uint32_t>>>
@@ -277,7 +277,7 @@
sdbusplus::bus::match::rules::interfacesAdded() +
sdbusplus::bus::match::rules::argNpath(0, certObjPath),
[this, hostSockFd, hostEid, dbusImplReqester,
- &handler](sdbusplus::message::message& msg) {
+ handler](sdbusplus::message::message& msg) {
std::map<
std::string,
std::map<std::string, std::variant<std::string, uint32_t>>>