Fix coredump when restart service if created subscriptions
When multiple subscriptions are created using the redfish url:
/redfish/v1/EventService/Subscriptions/, a coredump occurs during
the bmcweb restart process.
The problem was found when saving the subscription configuration
during the service stop process, remove the newly created shared
pointer 'subValue' and use the pointer in the map directly, this
problem was solved.
Tested: Create 18 subscriptions and restart the service 300 times
without coredump generation.
Change-Id: Ide90abdbc4c6e88215049783b88d9e91902c554d
Signed-off-by: wenlitao <w_litao@linux.alibaba.com>
diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp
index fc69aed..8ef3a6e 100644
--- a/include/persistent_data.hpp
+++ b/include/persistent_data.hpp
@@ -268,15 +268,15 @@
for (const auto& it :
EventServiceStore::getInstance().subscriptionsConfigMap)
{
- std::shared_ptr<UserSubscription> subValue = it.second;
- if (subValue->subscriptionType == "SSE")
+ const UserSubscription& subValue = *it.second;
+ if (subValue.subscriptionType == "SSE")
{
BMCWEB_LOG_DEBUG("The subscription type is SSE, so skipping.");
continue;
}
nlohmann::json::object_t headers;
for (const boost::beast::http::fields::value_type& header :
- subValue->httpHeaders)
+ subValue.httpHeaders)
{
// Note, these are technically copies because nlohmann doesn't
// support key lookup by std::string_view. At least the
@@ -288,19 +288,19 @@
nlohmann::json::object_t subscription;
- subscription["Id"] = subValue->id;
- subscription["Context"] = subValue->customText;
- subscription["DeliveryRetryPolicy"] = subValue->retryPolicy;
- subscription["Destination"] = subValue->destinationUrl;
- subscription["EventFormatType"] = subValue->eventFormatType;
+ subscription["Id"] = subValue.id;
+ subscription["Context"] = subValue.customText;
+ subscription["DeliveryRetryPolicy"] = subValue.retryPolicy;
+ subscription["Destination"] = subValue.destinationUrl;
+ subscription["EventFormatType"] = subValue.eventFormatType;
subscription["HttpHeaders"] = std::move(headers);
- subscription["MessageIds"] = subValue->registryMsgIds;
- subscription["Protocol"] = subValue->protocol;
- subscription["RegistryPrefixes"] = subValue->registryPrefixes;
- subscription["ResourceTypes"] = subValue->resourceTypes;
- subscription["SubscriptionType"] = subValue->subscriptionType;
+ subscription["MessageIds"] = subValue.registryMsgIds;
+ subscription["Protocol"] = subValue.protocol;
+ subscription["RegistryPrefixes"] = subValue.registryPrefixes;
+ subscription["ResourceTypes"] = subValue.resourceTypes;
+ subscription["SubscriptionType"] = subValue.subscriptionType;
subscription["MetricReportDefinitions"] =
- subValue->metricReportDefinitions;
+ subValue.metricReportDefinitions;
subscriptions.emplace_back(std::move(subscription));
}