Fix leaks in rcl_action unit tests (#442)
Fix memory leaks detected by AddressSanitizer from rcl_action unit tests. Signed-off-by: Prajakta Gokhale <prajaktg@amazon.com>
This commit is contained in:
parent
545076505b
commit
3806aa226d
5 changed files with 33 additions and 0 deletions
|
@ -170,6 +170,7 @@ if(BUILD_TESTING)
|
||||||
${PROJECT_NAME}
|
${PROJECT_NAME}
|
||||||
)
|
)
|
||||||
ament_target_dependencies(test_action_server
|
ament_target_dependencies(test_action_server
|
||||||
|
"osrf_testing_tools_cpp"
|
||||||
"rcl"
|
"rcl"
|
||||||
"test_msgs"
|
"test_msgs"
|
||||||
)
|
)
|
||||||
|
|
|
@ -52,6 +52,8 @@ protected:
|
||||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
ret = rcl_shutdown(&this->context);
|
ret = rcl_shutdown(&this->context);
|
||||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_context_fini(&this->context);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
}
|
}
|
||||||
|
|
||||||
rcl_context_t context;
|
rcl_context_t context;
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "osrf_testing_tools_cpp/scope_exit.hpp"
|
||||||
|
|
||||||
#include "rcl_action/action_client.h"
|
#include "rcl_action/action_client.h"
|
||||||
#include "rcl_action/action_server.h"
|
#include "rcl_action/action_server.h"
|
||||||
#include "rcl_action/wait.h"
|
#include "rcl_action/wait.h"
|
||||||
|
@ -41,6 +43,9 @@ protected:
|
||||||
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
|
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
|
||||||
ret = rcl_init_options_init(&init_options, allocator);
|
ret = rcl_init_options_init(&init_options, allocator);
|
||||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
|
||||||
|
EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str;
|
||||||
|
});
|
||||||
context = rcl_get_zero_initialized_context();
|
context = rcl_get_zero_initialized_context();
|
||||||
ret = rcl_init(0, nullptr, &init_options, &context);
|
ret = rcl_init(0, nullptr, &init_options, &context);
|
||||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
@ -119,6 +124,8 @@ protected:
|
||||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||||
ret = rcl_shutdown(&context);
|
ret = rcl_shutdown(&context);
|
||||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_context_fini(&this->context);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_test_uuid0(uint8_t * uuid)
|
void init_test_uuid0(uint8_t * uuid)
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "osrf_testing_tools_cpp/scope_exit.hpp"
|
||||||
|
|
||||||
#include "rcl_action/action_client.h"
|
#include "rcl_action/action_client.h"
|
||||||
#include "rcl_action/action_server.h"
|
#include "rcl_action/action_server.h"
|
||||||
#include "rcl_action/wait.h"
|
#include "rcl_action/wait.h"
|
||||||
|
@ -53,6 +55,9 @@ protected:
|
||||||
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
|
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
|
||||||
ret = rcl_init_options_init(&init_options, allocator);
|
ret = rcl_init_options_init(&init_options, allocator);
|
||||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
|
||||||
|
EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str;
|
||||||
|
});
|
||||||
context = rcl_get_zero_initialized_context();
|
context = rcl_get_zero_initialized_context();
|
||||||
ret = rcl_init(0, nullptr, &init_options, &context);
|
ret = rcl_init(0, nullptr, &init_options, &context);
|
||||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
@ -141,6 +146,8 @@ protected:
|
||||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||||
ret = rcl_shutdown(&context);
|
ret = rcl_shutdown(&context);
|
||||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_context_fini(&this->context);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_test_uuid0(uint8_t * uuid)
|
void init_test_uuid0(uint8_t * uuid)
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include "action_msgs/srv/cancel_goal.h"
|
#include "action_msgs/srv/cancel_goal.h"
|
||||||
|
|
||||||
|
#include "osrf_testing_tools_cpp/scope_exit.hpp"
|
||||||
|
|
||||||
#include "rcl_action/action_server.h"
|
#include "rcl_action/action_server.h"
|
||||||
|
|
||||||
#include "rcl/error_handling.h"
|
#include "rcl/error_handling.h"
|
||||||
|
@ -137,12 +139,21 @@ TEST(TestActionServerInitFini, test_action_server_init_fini)
|
||||||
ret = rcl_clock_fini(&clock);
|
ret = rcl_clock_fini(&clock);
|
||||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||||
|
|
||||||
|
// Finalize init_options
|
||||||
|
ret = rcl_init_options_fini(&init_options);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
|
||||||
// Finalize node
|
// Finalize node
|
||||||
ret = rcl_node_fini(&node);
|
ret = rcl_node_fini(&node);
|
||||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
|
||||||
|
// Shutdown node
|
||||||
ret = rcl_shutdown(&context);
|
ret = rcl_shutdown(&context);
|
||||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
|
||||||
|
// Finalize context
|
||||||
|
ret = rcl_context_fini(&context);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestActionServer : public ::testing::Test
|
class TestActionServer : public ::testing::Test
|
||||||
|
@ -155,6 +166,9 @@ protected:
|
||||||
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
|
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
|
||||||
ret = rcl_init_options_init(&init_options, allocator);
|
ret = rcl_init_options_init(&init_options, allocator);
|
||||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
|
||||||
|
EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str;
|
||||||
|
});
|
||||||
context = rcl_get_zero_initialized_context();
|
context = rcl_get_zero_initialized_context();
|
||||||
ret = rcl_init(0, nullptr, &init_options, &context);
|
ret = rcl_init(0, nullptr, &init_options, &context);
|
||||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
@ -185,6 +199,8 @@ protected:
|
||||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||||
ret = rcl_shutdown(&context);
|
ret = rcl_shutdown(&context);
|
||||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_context_fini(&this->context);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_test_uuid0(uint8_t * uuid)
|
void init_test_uuid0(uint8_t * uuid)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue