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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue