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:
parent
b40eff9b9e
commit
54d06f5654
3 changed files with 9 additions and 14 deletions
|
@ -45,6 +45,9 @@ typedef rcutils_error_state_t rcl_error_state_t;
|
|||
|
||||
#define RCL_SET_ERROR_MSG(msg, allocator) RCUTILS_SET_ERROR_MSG(msg, allocator)
|
||||
|
||||
#define RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(allocator, fmt_str, ...) \
|
||||
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(allocator, fmt_str, __VA_ARGS__)
|
||||
|
||||
#define rcl_error_is_set rcutils_error_is_set
|
||||
|
||||
#define rcl_get_error_state rcutils_get_error_state
|
||||
|
|
|
@ -166,20 +166,14 @@ rcl_expand_topic_name(
|
|||
*output_topic_name = NULL;
|
||||
char * unmatched_substitution =
|
||||
rcutils_strndup(next_opening_brace, substitution_substr_len, allocator);
|
||||
char * allocated_msg = NULL;
|
||||
char * msg = NULL;
|
||||
if (unmatched_substitution) {
|
||||
allocated_msg = rcutils_format_string(
|
||||
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
|
||||
allocator,
|
||||
"unknown substitution: %s", unmatched_substitution);
|
||||
msg = allocated_msg;
|
||||
} else {
|
||||
RCUTILS_SAFE_FWRITE_TO_STDERR("failed to allocate memory for error message\n");
|
||||
msg = "unknown substitution: allocation failed when reporting error";
|
||||
RCUTILS_SAFE_FWRITE_TO_STDERR("failed to allocate memory for unmatched substitution\n");
|
||||
}
|
||||
RCL_SET_ERROR_MSG(msg, allocator)
|
||||
allocator.deallocate(unmatched_substitution, allocator.state);
|
||||
allocator.deallocate(allocated_msg, allocator.state);
|
||||
allocator.deallocate(local_output, allocator.state);
|
||||
return RCL_RET_UNKNOWN_SUBSTITUTION;
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(rcutils_get_default_allocator(),
|
||||
"state %u is already registered\n", state.id);
|
||||
RCL_SET_ERROR_MSG(error_msg, rcutils_get_default_allocator());
|
||||
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(),
|
||||
RCL_SET_ERROR_MSG_WITH_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());
|
||||
return RCL_RET_ERROR;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue