Skip to content

Commit

Permalink
network_manager: Explicitly capture references in cb
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wak-google committed Sep 8, 2023
1 parent 9caa64d commit 5c1e160
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/network_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Manager::Manager(stdplus::PinnedRef<sdbusplus::bus_t> bus,
}
})
{
reload.get().setCallback([&]() {
for (auto& hook : reloadPreHooks)
reload.get().setCallback([self = stdplus::PinnedRef(*this)]() {
for (auto& hook : self.get().reloadPreHooks)
{
try
{
Expand All @@ -88,10 +88,11 @@ Manager::Manager(stdplus::PinnedRef<sdbusplus::bus_t> 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")
Expand All @@ -101,9 +102,9 @@ Manager::Manager(stdplus::PinnedRef<sdbusplus::bus_t> 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
{
Expand All @@ -115,7 +116,7 @@ Manager::Manager(stdplus::PinnedRef<sdbusplus::bus_t> bus,
"ERROR", ex);
}
}
reloadPostHooks.clear();
self.get().reloadPostHooks.clear();
});
std::vector<
std::tuple<int32_t, std::string, sdbusplus::message::object_path>>
Expand Down

0 comments on commit 5c1e160

Please sign in to comment.