Skip to content

Commit ec3ab12

Browse files
y-okumura-ispjacobperron
authored andcommitted
Fix memory leak in test_publisher, not fini publisher (#469)
Signed-off-by: y-okumura-isp <[email protected]>
1 parent 0200a58 commit ec3ab12

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

rcl/test/rcl/test_publisher.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
202202
ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &default_publisher_options);
203203
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
204204
EXPECT_TRUE(rcl_publisher_is_valid(&publisher));
205+
ret = rcl_publisher_fini(&publisher, this->node_ptr);
206+
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
205207
rcl_reset_error();
206208

207209
// Try passing null for publisher in init.
@@ -213,32 +215,42 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
213215
publisher = rcl_get_zero_initialized_publisher();
214216
ret = rcl_publisher_init(&publisher, nullptr, ts, topic_name, &default_publisher_options);
215217
EXPECT_EQ(RCL_RET_NODE_INVALID, ret) << rcl_get_error_string().str;
218+
ret = rcl_publisher_fini(&publisher, this->node_ptr);
219+
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
216220
rcl_reset_error();
217221

218222
// Try passing an invalid (uninitialized) node in init.
219223
publisher = rcl_get_zero_initialized_publisher();
220224
rcl_node_t invalid_node = rcl_get_zero_initialized_node();
221225
ret = rcl_publisher_init(&publisher, &invalid_node, ts, topic_name, &default_publisher_options);
222226
EXPECT_EQ(RCL_RET_NODE_INVALID, ret) << rcl_get_error_string().str;
227+
ret = rcl_publisher_fini(&publisher, this->node_ptr);
228+
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
223229
rcl_reset_error();
224230

225231
// Try passing null for the type support in init.
226232
publisher = rcl_get_zero_initialized_publisher();
227233
ret = rcl_publisher_init(
228234
&publisher, this->node_ptr, nullptr, topic_name, &default_publisher_options);
229235
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
236+
ret = rcl_publisher_fini(&publisher, this->node_ptr);
237+
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
230238
rcl_reset_error();
231239

232240
// Try passing null for the topic name in init.
233241
publisher = rcl_get_zero_initialized_publisher();
234242
ret = rcl_publisher_init(&publisher, this->node_ptr, ts, nullptr, &default_publisher_options);
235243
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
244+
ret = rcl_publisher_fini(&publisher, this->node_ptr);
245+
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
236246
rcl_reset_error();
237247

238248
// Try passing null for the options in init.
239249
publisher = rcl_get_zero_initialized_publisher();
240250
ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, nullptr);
241251
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
252+
ret = rcl_publisher_fini(&publisher, this->node_ptr);
253+
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
242254
rcl_reset_error();
243255

244256
// Try passing options with an invalid allocate in allocator with init.
@@ -249,6 +261,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
249261
ret = rcl_publisher_init(
250262
&publisher, this->node_ptr, ts, topic_name, &publisher_options_with_invalid_allocator);
251263
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
264+
ret = rcl_publisher_fini(&publisher, this->node_ptr);
265+
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
252266
rcl_reset_error();
253267

254268
// Try passing options with an invalid deallocate in allocator with init.
@@ -258,6 +272,8 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
258272
ret = rcl_publisher_init(
259273
&publisher, this->node_ptr, ts, topic_name, &publisher_options_with_invalid_allocator);
260274
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
275+
ret = rcl_publisher_fini(&publisher, this->node_ptr);
276+
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
261277
rcl_reset_error();
262278

263279
// An allocator with an invalid realloc will probably work (so we will not test it).

0 commit comments

Comments
 (0)