Fix test_publisher memory leaks reported by asan (#567)
* Fix memory leak in test_publisher, test msg not released (#469) Signed-off-by: y-okumura-isp <y-okumura@isp.co.jp> * Fix memory leak in test_publisher, not fini publisher (#469) Signed-off-by: y-okumura-isp <y-okumura@isp.co.jp>
This commit is contained in:
parent
ccb4ec7a71
commit
3142616db4
1 changed files with 17 additions and 0 deletions
|
@ -173,6 +173,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publishers_diff
|
||||||
test_msgs__msg__Strings__init(&msg_string);
|
test_msgs__msg__Strings__init(&msg_string);
|
||||||
ASSERT_TRUE(rosidl_runtime_c__String__assign(&msg_string.string_value, "testing"));
|
ASSERT_TRUE(rosidl_runtime_c__String__assign(&msg_string.string_value, "testing"));
|
||||||
ret = rcl_publish(&publisher_in_namespace, &msg_string, nullptr);
|
ret = rcl_publish(&publisher_in_namespace, &msg_string, nullptr);
|
||||||
|
test_msgs__msg__Strings__fini(&msg_string);
|
||||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,6 +202,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
|
||||||
ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &default_publisher_options);
|
ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &default_publisher_options);
|
||||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
EXPECT_TRUE(rcl_publisher_is_valid(&publisher));
|
EXPECT_TRUE(rcl_publisher_is_valid(&publisher));
|
||||||
|
ret = rcl_publisher_fini(&publisher, this->node_ptr);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
rcl_reset_error();
|
rcl_reset_error();
|
||||||
|
|
||||||
// Try passing null for publisher in init.
|
// Try passing null for publisher in init.
|
||||||
|
@ -212,6 +215,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
|
||||||
publisher = rcl_get_zero_initialized_publisher();
|
publisher = rcl_get_zero_initialized_publisher();
|
||||||
ret = rcl_publisher_init(&publisher, nullptr, ts, topic_name, &default_publisher_options);
|
ret = rcl_publisher_init(&publisher, nullptr, ts, topic_name, &default_publisher_options);
|
||||||
EXPECT_EQ(RCL_RET_NODE_INVALID, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_NODE_INVALID, ret) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_publisher_fini(&publisher, this->node_ptr);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
rcl_reset_error();
|
rcl_reset_error();
|
||||||
|
|
||||||
// Try passing an invalid (uninitialized) node in init.
|
// Try passing an invalid (uninitialized) node in init.
|
||||||
|
@ -219,6 +224,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
|
||||||
rcl_node_t invalid_node = rcl_get_zero_initialized_node();
|
rcl_node_t invalid_node = rcl_get_zero_initialized_node();
|
||||||
ret = rcl_publisher_init(&publisher, &invalid_node, ts, topic_name, &default_publisher_options);
|
ret = rcl_publisher_init(&publisher, &invalid_node, ts, topic_name, &default_publisher_options);
|
||||||
EXPECT_EQ(RCL_RET_NODE_INVALID, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_NODE_INVALID, ret) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_publisher_fini(&publisher, this->node_ptr);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
rcl_reset_error();
|
rcl_reset_error();
|
||||||
|
|
||||||
// Try passing null for the type support in init.
|
// Try passing null for the type support in init.
|
||||||
|
@ -226,18 +233,24 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
|
||||||
ret = rcl_publisher_init(
|
ret = rcl_publisher_init(
|
||||||
&publisher, this->node_ptr, nullptr, topic_name, &default_publisher_options);
|
&publisher, this->node_ptr, nullptr, topic_name, &default_publisher_options);
|
||||||
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_publisher_fini(&publisher, this->node_ptr);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
rcl_reset_error();
|
rcl_reset_error();
|
||||||
|
|
||||||
// Try passing null for the topic name in init.
|
// Try passing null for the topic name in init.
|
||||||
publisher = rcl_get_zero_initialized_publisher();
|
publisher = rcl_get_zero_initialized_publisher();
|
||||||
ret = rcl_publisher_init(&publisher, this->node_ptr, ts, nullptr, &default_publisher_options);
|
ret = rcl_publisher_init(&publisher, this->node_ptr, ts, nullptr, &default_publisher_options);
|
||||||
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_publisher_fini(&publisher, this->node_ptr);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
rcl_reset_error();
|
rcl_reset_error();
|
||||||
|
|
||||||
// Try passing null for the options in init.
|
// Try passing null for the options in init.
|
||||||
publisher = rcl_get_zero_initialized_publisher();
|
publisher = rcl_get_zero_initialized_publisher();
|
||||||
ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, nullptr);
|
ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, nullptr);
|
||||||
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_publisher_fini(&publisher, this->node_ptr);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
rcl_reset_error();
|
rcl_reset_error();
|
||||||
|
|
||||||
// Try passing options with an invalid allocate in allocator with init.
|
// Try passing options with an invalid allocate in allocator with init.
|
||||||
|
@ -248,6 +261,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
|
||||||
ret = rcl_publisher_init(
|
ret = rcl_publisher_init(
|
||||||
&publisher, this->node_ptr, ts, topic_name, &publisher_options_with_invalid_allocator);
|
&publisher, this->node_ptr, ts, topic_name, &publisher_options_with_invalid_allocator);
|
||||||
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_publisher_fini(&publisher, this->node_ptr);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
rcl_reset_error();
|
rcl_reset_error();
|
||||||
|
|
||||||
// Try passing options with an invalid deallocate in allocator with init.
|
// Try passing options with an invalid deallocate in allocator with init.
|
||||||
|
@ -257,6 +272,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
|
||||||
ret = rcl_publisher_init(
|
ret = rcl_publisher_init(
|
||||||
&publisher, this->node_ptr, ts, topic_name, &publisher_options_with_invalid_allocator);
|
&publisher, this->node_ptr, ts, topic_name, &publisher_options_with_invalid_allocator);
|
||||||
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
||||||
|
ret = rcl_publisher_fini(&publisher, this->node_ptr);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
rcl_reset_error();
|
rcl_reset_error();
|
||||||
|
|
||||||
// An allocator with an invalid realloc will probably work (so we will not test it).
|
// An allocator with an invalid realloc will probably work (so we will not test it).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue