remove potential memory leak with getAllProperties
Wrap handler in a lambda to remove the trigger potential memory
leak with clang-tidy. Only getAllProperties have this std::move to
async_method_call and is hitting the issue.
The issue only happens if the handler captures some variabls
Example code that hit the issue.
```
void handler(const std::string& /*unused*/,
const boost::system::error_code /*unused*/,
const std::vector<
std::pair<std::string, std::variant<std::string>>>& /*unused*/)
{}
void test(sdbusplus::asio::connection* conn)
{
std::string test = "test";
sdbusplus::asio::getAllProperties<std::variant<std::string>>(
*conn, "xyz.openbmc_project.EntityManager", "path",
"xyz.openbmc_project.Inventory.Decorator.Asset",
std::bind_front(handler, test));
}
```
Tested:
clang-tidy is happy now
Signed-off-by: Willy Tu <wltu@google.com>
Change-Id: I0a3a5ed016aed664c650d811e253d54a4eb2b0b1
diff --git a/include/sdbusplus/asio/property.hpp b/include/sdbusplus/asio/property.hpp
index 509bb77..c528afe 100644
--- a/include/sdbusplus/asio/property.hpp
+++ b/include/sdbusplus/asio/property.hpp
@@ -17,9 +17,12 @@
{
static_assert(std::is_same_v<VariantType, std::decay_t<VariantType>>);
- bus.async_method_call(std::move(handler), service, path,
- "org.freedesktop.DBus.Properties", "GetAll",
- interface);
+ bus.async_method_call(
+ [handler = std::move(handler)](
+ const boost::system::error_code ec,
+ const std::vector<std::pair<std::string, VariantType>>&
+ data) mutable { handler(ec, data); },
+ service, path, "org.freedesktop.DBus.Properties", "GetAll", interface);
}
template <typename Handler>