diff options
author | William A. Kennington III <wak@google.com> | 2018-06-19 18:36:41 -0700 |
---|---|---|
committer | William A. Kennington III <wak@google.com> | 2018-06-27 10:11:38 -0700 |
commit | b5645509cad3f6a3c5c869a69e6c25f17a7ea830 (patch) | |
tree | 699fd375086daf8febf80f157253a8339cb18312 | |
parent | c65d74eda8c30548635e7ba69914299efa132b28 (diff) | |
download | sdbusplus-b5645509cad3f6a3c5c869a69e6c25f17a7ea830.tar.gz sdbusplus-b5645509cad3f6a3c5c869a69e6c25f17a7ea830.zip |
tests: Fix memory leak from sd_bus calls
Some of the calls into sd_bus leak memory because they never unreference
the bus or messages. Fix this so we can eventually enable leak checking
from valgrind.
Tested:
Ran through valgrind and the errors went away.
Change-Id: Icc3d5d0860b3852401219c1ca511a1bc26aa1c48
Signed-off-by: William A. Kennington III <wak@google.com>
-rw-r--r-- | test/message/append.cpp | 6 | ||||
-rw-r--r-- | test/message/read.cpp | 11 |
2 files changed, 13 insertions, 4 deletions
diff --git a/test/message/append.cpp b/test/message/append.cpp index c56402a..b067e18 100644 --- a/test/message/append.cpp +++ b/test/message/append.cpp @@ -28,7 +28,8 @@ auto serverInit() // Thread to run the dbus server. void* server(void* b) { - auto bus = sdbusplus::bus::bus(reinterpret_cast<sdbusplus::bus::busp_t>(b)); + auto bus = sdbusplus::bus::bus(reinterpret_cast<sdbusplus::bus::busp_t>(b), + std::false_type()); while (1) { @@ -62,8 +63,11 @@ void* server(void* b) { // Reply and exit. sd_bus_reply_method_return(m, nullptr); + sd_bus_message_unref(m); break; } + + sd_bus_message_unref(m); } return nullptr; diff --git a/test/message/read.cpp b/test/message/read.cpp index cd31b61..4eb6437 100644 --- a/test/message/read.cpp +++ b/test/message/read.cpp @@ -28,7 +28,8 @@ auto serverInit() // Thread to run the dbus server. void* server(void* b) { - auto bus = sdbusplus::bus::bus(reinterpret_cast<sdbusplus::bus::busp_t>(b)); + auto bus = sdbusplus::bus::bus(reinterpret_cast<sdbusplus::bus::busp_t>(b), + std::false_type()); while (1) { @@ -58,12 +59,16 @@ void* server(void* b) << std::endl; } // Reply to client. - sd_bus_reply_method_return(m.release(), nullptr); + auto sd_m = m.release(); + sd_bus_reply_method_return(sd_m, nullptr); + sd_bus_message_unref(sd_m); } else if (m.is_method_call(INTERFACE, QUIT_METHOD)) { // Reply and exit. - sd_bus_reply_method_return(m.release(), nullptr); + auto sd_m = m.release(); + sd_bus_reply_method_return(sd_m, nullptr); + sd_bus_message_unref(sd_m); break; } } |