Fix crash on subscriptions

When the subscription limit is hit, there is Subscription events
generated when Subscription objects are constructed.  Unfortunately, we
make an accidental copy of the Subscription object in
include/persistent_data.hpp

https://gerrit.openbmc.org/c/openbmc/bmcweb/+/72670

Is lined up to fix that issue, but we need to fix the underlying problem
where we have memory safety issues in global variables.

This commit is something to fix the issue, by simply destroying the
object causing the problem before more events can be received.

Tested:
Followed instructions on the aforementioned commit to create the max
number of subscriptions.
Called systemctl restart bmcweb

Observed no more crash on shutdown.

Change-Id: Ie52545f5cb8a044c186d0e9db47362e170b1fdb5
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 9ab578d..93ebc88 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -1123,6 +1123,11 @@
         inotifyConn->async_read_some(boost::asio::buffer(readBuffer),
                                      [&](const boost::system::error_code& ec,
                                          const std::size_t& bytesTransferred) {
+            if (ec == boost::asio::error::operation_aborted)
+            {
+                BMCWEB_LOG_DEBUG("Inotify was canceled (shutdown?)");
+                return;
+            }
             if (ec)
             {
                 BMCWEB_LOG_ERROR("Callback Error: {}", ec.message());
@@ -1243,6 +1248,11 @@
         return 0;
     }
 
+    static void stopEventLogMonitor()
+    {
+        inotifyConn.reset();
+    }
+
     static void getReadingsForReport(sdbusplus::message_t& msg)
     {
         if (msg.is_method_error())
diff --git a/src/webserver_run.cpp b/src/webserver_run.cpp
index 29683b9..5013669 100644
--- a/src/webserver_run.cpp
+++ b/src/webserver_run.cpp
@@ -110,5 +110,8 @@
 
     crow::connections::systemBus = nullptr;
 
+    // TODO(ed) Make event log monitor an RAII object instead of global vars
+    redfish::EventServiceManager::stopEventLogMonitor();
+
     return 0;
 }