fix leak in test_init (#440)

Signed-off-by: Abby Xu <abbyxu@amazon.com>
This commit is contained in:
Abby Xu 2019-05-16 15:56:20 -07:00 committed by Dirk Thomas
parent 2f6abbb0ee
commit 2380a1a3a8

View file

@ -57,7 +57,7 @@ public:
struct FakeTestArgv struct FakeTestArgv
{ {
FakeTestArgv() FakeTestArgv()
: allocator(rcutils_get_default_allocator()), argc(2) : allocator(rcl_get_default_allocator()), argc(2)
{ {
this->argv = this->argv =
static_cast<char **>(allocator.allocate(2 * sizeof(char *), allocator.state)); static_cast<char **>(allocator.allocate(2 * sizeof(char *), allocator.state));
@ -82,7 +82,7 @@ struct FakeTestArgv
if (this->argv) { if (this->argv) {
if (this->argc > 0) { if (this->argc > 0) {
size_t unsigned_argc = this->argc; size_t unsigned_argc = this->argc;
for (size_t i = 0; i < unsigned_argc; --i) { for (size_t i = 0; i < unsigned_argc; ++i) {
allocator.deallocate(this->argv[i], allocator.state); allocator.deallocate(this->argv[i], allocator.state);
} }
} }
@ -90,7 +90,7 @@ struct FakeTestArgv
allocator.deallocate(this->argv, allocator.state); allocator.deallocate(this->argv, allocator.state);
} }
rcutils_allocator_t allocator; rcl_allocator_t allocator;
int argc; int argc;
char ** argv; char ** argv;
@ -201,6 +201,9 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_and_ok_and_s
ret = rcl_context_fini(&context); ret = rcl_context_fini(&context);
EXPECT_EQ(ret, RCL_RET_OK); EXPECT_EQ(ret, RCL_RET_OK);
context = rcl_get_zero_initialized_context(); context = rcl_get_zero_initialized_context();
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str;
});
} }
/* Tests the rcl_get_instance_id() and rcl_ok() functions. /* Tests the rcl_get_instance_id() and rcl_ok() functions.