From 5c1e1604ff9637630a7338392e37ba9d3fc2b359 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Fri, 8 Sep 2023 13:26:56 -0700 Subject: [PATCH] network_manager: Explicitly capture references in cb We were accidentally capturing a reference to a stack variable and not guaranteeing that we have an unmoving reference to the object being referenced in the callback. Change-Id: Ib16d264a5a1170ac6d11979d32800dce90a11a33 Signed-off-by: William A. Kennington III --- src/network_manager.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/network_manager.cpp b/src/network_manager.cpp index 47a528f08..5206e366f 100644 --- a/src/network_manager.cpp +++ b/src/network_manager.cpp @@ -75,8 +75,8 @@ Manager::Manager(stdplus::PinnedRef bus, } }) { - reload.get().setCallback([&]() { - for (auto& hook : reloadPreHooks) + reload.get().setCallback([self = stdplus::PinnedRef(*this)]() { + for (auto& hook : self.get().reloadPreHooks) { try { @@ -88,10 +88,11 @@ Manager::Manager(stdplus::PinnedRef bus, "ERROR", ex); } } - reloadPreHooks.clear(); + self.get().reloadPreHooks.clear(); try { - bus.get() + self.get() + .bus.get() .new_method_call("org.freedesktop.network1", "/org/freedesktop/network1", "org.freedesktop.network1.Manager", "Reload") @@ -101,9 +102,9 @@ Manager::Manager(stdplus::PinnedRef bus, catch (const sdbusplus::exception_t& ex) { lg2::error("Failed to reload configuration: {ERROR}", "ERROR", ex); - reloadPostHooks.clear(); + self.get().reloadPostHooks.clear(); } - for (auto& hook : reloadPostHooks) + for (auto& hook : self.get().reloadPostHooks) { try { @@ -115,7 +116,7 @@ Manager::Manager(stdplus::PinnedRef bus, "ERROR", ex); } } - reloadPostHooks.clear(); + self.get().reloadPostHooks.clear(); }); std::vector< std::tuple>