From 80e500b771dd0ebbdca0dd1d7840e46a557459c6 Mon Sep 17 00:00:00 2001 From: Mikael Arguedas Date: Tue, 28 Nov 2017 15:01:22 -0800 Subject: [PATCH] Waitset member allocation use rmw types (#190) * allocate memory for rmw types and not rcl types in waitset RMW storage * zero initialize memory on resize and clear * add missing void * cast to make windows happy * set mem after checking successful alloc and use right type for rmw storage * another instance of cast to (rmw_ ## Type ## _t *) instead of (void *) --- rcl/src/rcl/wait.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rcl/src/rcl/wait.c b/rcl/src/rcl/wait.c index e5a72af..cc66f27 100644 --- a/rcl/src/rcl/wait.c +++ b/rcl/src/rcl/wait.c @@ -283,7 +283,7 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al memset( \ wait_set->impl->RMWStorage, \ 0, \ - sizeof(rmw_ ## Type ## _t *) * wait_set->impl->RMWCount); \ + sizeof(void *) * wait_set->impl->RMWCount); \ wait_set->impl->RMWCount = 0; #define SET_RESIZE(Type, ExtraDealloc, ExtraRealloc) \ @@ -308,6 +308,7 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al RCL_CHECK_FOR_NULL_WITH_MSG( \ wait_set->Type ## s, "allocating memory failed", \ return RCL_RET_BAD_ALLOC, wait_set->impl->allocator); \ + memset((void *)wait_set->Type ## s, 0, sizeof(rcl_ ## Type ## _t *) * size); \ wait_set->size_of_ ## Type ## s = size; \ ExtraRealloc \ } \ @@ -324,13 +325,14 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al /* Also resize the rmw storage. */ \ wait_set->impl->RMWCount = 0; \ wait_set->impl->RMWStorage = (void **)allocator.reallocate( \ - wait_set->impl->RMWStorage, sizeof(rcl_ ## Type ## _t *) * size, allocator.state); \ + wait_set->impl->RMWStorage, sizeof(void *) * size, allocator.state); \ if (!wait_set->impl->RMWStorage) { \ allocator.deallocate((void *)wait_set->Type ## s, allocator.state); \ wait_set->size_of_ ## Type ## s = 0; \ RCL_SET_ERROR_MSG("allocating memory failed", wait_set->impl->allocator); \ return RCL_RET_BAD_ALLOC; \ - } + } \ + memset(wait_set->impl->RMWStorage, 0, sizeof(void *) * size); /* Implementation-specific notes: *