From 064a24b554a510c8f6617476134d9069c7b0959f Mon Sep 17 00:00:00 2001 From: y-okumura-isp Date: Mon, 3 Feb 2020 17:31:43 +0900 Subject: [PATCH] Fix memory leak in test_publisher, not fini publisher (#469) Signed-off-by: y-okumura-isp --- rcl/test/rcl/test_publisher.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index bd607a50f..22bc33e62 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -197,6 +197,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_ 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_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(); // Try passing null for publisher in init. @@ -208,6 +210,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_ publisher = rcl_get_zero_initialized_publisher(); ret = rcl_publisher_init(&publisher, nullptr, ts, topic_name, &default_publisher_options); 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(); // Try passing an invalid (uninitialized) node in init. @@ -215,6 +219,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_ rcl_node_t invalid_node = rcl_get_zero_initialized_node(); 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; + ret = rcl_publisher_fini(&publisher, this->node_ptr); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; rcl_reset_error(); // Try passing null for the type support in init. @@ -222,18 +228,24 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_ ret = rcl_publisher_init( &publisher, this->node_ptr, nullptr, topic_name, &default_publisher_options); 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(); // Try passing null for the topic name in init. publisher = rcl_get_zero_initialized_publisher(); 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; + ret = rcl_publisher_fini(&publisher, this->node_ptr); + EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; rcl_reset_error(); // Try passing null for the options in init. publisher = rcl_get_zero_initialized_publisher(); ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, nullptr); 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(); // Try passing options with an invalid allocate in allocator with init. @@ -244,6 +256,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_ ret = rcl_publisher_init( &publisher, this->node_ptr, ts, topic_name, &publisher_options_with_invalid_allocator); 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(); // Try passing options with an invalid deallocate in allocator with init. @@ -253,6 +267,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_ ret = rcl_publisher_init( &publisher, this->node_ptr, ts, topic_name, &publisher_options_with_invalid_allocator); 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(); // An allocator with an invalid realloc will probably work (so we will not test it).