Skip to content

Commit

Permalink
fix leak in node.c (#424)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
xabxx authored and sloretz committed May 3, 2019
1 parent 452309f commit ec878a4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion rcl/include/rcl/security_directory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion rcl/src/rcl/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -408,6 +409,7 @@ rcl_node_init(
if (NULL != remapped_node_name) {
allocator->deallocate(remapped_node_name, allocator->state);
}
allocator->deallocate(node_secure_root, allocator->state);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion rcl/src/rcl/security_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ec878a4

Please sign in to comment.