Str mem leak rebased (#185)

* * memory leak issues

address those memory leak issues with the API
rcutils_set_formatted_error which is defined
in rcutils

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>

* * Address those memory leak issues with new MACRO
add macro RCL_SET_ERROR_MSG_WITH_FORMAT_STRING which
is equals RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING and
fix the memory leak issues with it

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>

* address uncrustify grumble

Signed-off-by: Ethan Gao <ethan.gao@linux.intel.com>
This commit is contained in:
Ethan Gao 2017-11-17 15:25:02 +08:00 committed by Mikael Arguedas
parent b40eff9b9e
commit 54d06f5654
3 changed files with 9 additions and 14 deletions

View file

@ -77,9 +77,8 @@ rcl_lifecycle_register_state(
const rcutils_allocator_t * allocator)
{
if (rcl_lifecycle_get_state(transition_map, state.id) != NULL) {
char * error_msg = rcutils_format_string(rcutils_get_default_allocator(),
"state %u is already registered\n", state.id);
RCL_SET_ERROR_MSG(error_msg, rcutils_get_default_allocator());
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(rcutils_get_default_allocator(),
"state %u is already registered\n", state.id);
return RCL_RET_ERROR;
}
@ -115,9 +114,8 @@ rcl_lifecycle_register_transition(
rcl_lifecycle_state_t * state = rcl_lifecycle_get_state(transition_map, transition.start->id);
if (!state) {
char * error_msg = rcutils_format_string(rcl_get_default_allocator(),
"state %u is not registered\n", transition.start->id);
RCL_SET_ERROR_MSG(error_msg, rcl_get_default_allocator());
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(rcl_get_default_allocator(),
"state %u is not registered\n", transition.start->id);
return RCL_RET_ERROR;
}