fix leak in node.c (#424)

* fix leak in node.c

Signed-off-by: Abby Xu <abbyxu@amazon.com>

* add comment for rcl_get_secure_root

Signed-off-by: Abby Xu <abbyxu@amazon.com>
This commit is contained in:
Abby Xu 2019-05-03 16:05:18 -07:00 committed by Shane Loretz
parent 452309f1ce
commit ec878a4781
3 changed files with 6 additions and 3 deletions

View file

@ -51,9 +51,10 @@ extern "C"
* \param[in] node_namespace validated, absolute namespace (starting with "/")
* \param[in] allocator the allocator to use for allocation
* \returns machine specific (absolute) node secure root path or NULL on failure
* returned pointer must be deallocated by the caller of this function
*/
RCL_PUBLIC
const char * rcl_get_secure_root(
char * rcl_get_secure_root(
const char * node_name,
const char * node_namespace,
const rcl_allocator_t * allocator

View file

@ -126,6 +126,7 @@ rcl_node_init(
rcl_ret_t ret;
rcl_ret_t fail_ret = RCL_RET_ERROR;
char * remapped_node_name = NULL;
char * node_secure_root = NULL;
// Check options and allocator first, so allocator can be used for errors.
RCL_CHECK_ARGUMENT_FOR_NULL(options, RCL_RET_INVALID_ARGUMENT);
@ -306,7 +307,7 @@ rcl_node_init(
node_security_options.enforce_security = RMW_SECURITY_ENFORCEMENT_PERMISSIVE;
} else { // if use_security
// File discovery magic here
const char * node_secure_root = rcl_get_secure_root(name, local_namespace_, allocator);
node_secure_root = rcl_get_secure_root(name, local_namespace_, allocator);
if (node_secure_root) {
RCUTILS_LOG_INFO_NAMED(ROS_PACKAGE_NAME, "Found security directory: %s", node_secure_root);
node_security_options.security_root_path = node_secure_root;
@ -408,6 +409,7 @@ cleanup:
if (NULL != remapped_node_name) {
allocator->deallocate(remapped_node_name, allocator->state);
}
allocator->deallocate(node_secure_root, allocator->state);
return ret;
}

View file

@ -173,7 +173,7 @@ char * prefix_match_lookup(
return node_secure_root;
}
const char * rcl_get_secure_root(
char * rcl_get_secure_root(
const char * node_name,
const char * node_namespace,
const rcl_allocator_t * allocator)