Fix static unordered_map may lead to segfault issue
When inserting element to static unordered_map, it
may cause segfault unexpectedly. Move their declaration
to the Nvme class to avoid this issue
Signed-off-by: George Hung <george.hung@quantatw.com>
Change-Id: I8d2b15e735b4140210118544c4648d0c221f1d6b
diff --git a/nvme_manager.cpp b/nvme_manager.cpp
index ccd2b60..e9e4328 100644
--- a/nvme_manager.cpp
+++ b/nvme_manager.cpp
@@ -164,7 +164,6 @@
bool success,
const phosphor::nvme::Nvme::NVMeData& nvmeData)
{
- static std::unordered_map<std::string, bool> isError;
if (success)
{
@@ -209,7 +208,8 @@
}
/** @brief Get NVMe info over smbus */
-bool getNVMeInfobyBusID(int busID, phosphor::nvme::Nvme::NVMeData& nvmeData)
+bool Nvme::getNVMeInfobyBusID(int busID,
+ phosphor::nvme::Nvme::NVMeData& nvmeData)
{
nvmeData.present = true;
nvmeData.vendor = "";
@@ -230,8 +230,6 @@
auto init = smbus.smbusInit(busID);
- static std::unordered_map<int, bool> isErrorSmbus;
-
if (init == -1)
{
if (isErrorSmbus[busID] != true)
@@ -578,8 +576,6 @@
std::string devPwrGoodPath;
std::string inventoryPath;
- static std::unordered_map<std::string, bool> isErrorPower;
-
for (auto config : configs)
{
NVMeData nvmeData;
diff --git a/nvme_manager.hpp b/nvme_manager.hpp
index 97ef204..78eabe3 100644
--- a/nvme_manager.hpp
+++ b/nvme_manager.hpp
@@ -124,6 +124,10 @@
void createNVMeInventory();
+ /** @brief read NVMe information via Smbus */
+ bool getNVMeInfobyBusID(int busID,
+ phosphor::nvme::Nvme::NVMeData& nvmeData);
+
/** @brief read and update NVME data to dbus */
void readNvmeData(NVMeConfig& config);
@@ -137,6 +141,13 @@
std::vector<phosphor::nvme::Nvme::NVMeConfig> configs;
+ /** @brief error status for Smbus */
+ std::unordered_map<int, bool> isErrorSmbus;
+ /** @brief error status for LED */
+ std::unordered_map<std::string, bool> isError;
+ /** @brief error status for NVMe power*/
+ std::unordered_map<std::string, bool> isErrorPower;
+
/** @brief Set up initial configuration value of NVMe */
void init();
/** @brief Monitor NVMe drives every one second */