Skip to content

Commit 9e5108c

Browse files
committed
fix leak in node.c
Signed-off-by: Abby Xu <[email protected]>
1 parent 3d48555 commit 9e5108c

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

rcl/include/rcl/security_directory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern "C"
5353
* \returns machine specific (absolute) node secure root path or NULL on failure
5454
*/
5555
RCL_PUBLIC
56-
const char * rcl_get_secure_root(
56+
char * rcl_get_secure_root(
5757
const char * node_name,
5858
const char * node_namespace,
5959
const rcl_allocator_t * allocator

rcl/src/rcl/node.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ rcl_node_init(
126126
rcl_ret_t ret;
127127
rcl_ret_t fail_ret = RCL_RET_ERROR;
128128
char * remapped_node_name = NULL;
129+
char * node_secure_root = NULL;
129130

130131
// Check options and allocator first, so allocator can be used for errors.
131132
RCL_CHECK_ARGUMENT_FOR_NULL(options, RCL_RET_INVALID_ARGUMENT);
@@ -306,7 +307,7 @@ rcl_node_init(
306307
node_security_options.enforce_security = RMW_SECURITY_ENFORCEMENT_PERMISSIVE;
307308
} else { // if use_security
308309
// File discovery magic here
309-
const char * node_secure_root = rcl_get_secure_root(name, local_namespace_, allocator);
310+
node_secure_root = rcl_get_secure_root(name, local_namespace_, allocator);
310311
if (node_secure_root) {
311312
RCUTILS_LOG_INFO_NAMED(ROS_PACKAGE_NAME, "Found security directory: %s", node_secure_root);
312313
node_security_options.security_root_path = node_secure_root;
@@ -408,6 +409,7 @@ rcl_node_init(
408409
if (NULL != remapped_node_name) {
409410
allocator->deallocate(remapped_node_name, allocator->state);
410411
}
412+
allocator->deallocate(node_secure_root, allocator->state);
411413
return ret;
412414
}
413415

rcl/src/rcl/security_directory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ char * prefix_match_lookup(
173173
return node_secure_root;
174174
}
175175

176-
const char * rcl_get_secure_root(
176+
char * rcl_get_secure_root(
177177
const char * node_name,
178178
const char * node_namespace,
179179
const rcl_allocator_t * allocator)

0 commit comments

Comments
 (0)