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;