@@ -59,6 +59,7 @@ typedef struct rcl_node_impl_t
5959 rmw_node_t * rmw_node_handle ;
6060 rcl_guard_condition_t * graph_guard_condition ;
6161 const char * logger_name ;
62+ const char * fq_name ;
6263} rcl_node_impl_t ;
6364
6465
@@ -284,6 +285,7 @@ rcl_node_init(
284285 node -> impl -> rmw_node_handle = NULL ;
285286 node -> impl -> graph_guard_condition = NULL ;
286287 node -> impl -> logger_name = NULL ;
288+ node -> impl -> fq_name = NULL ;
287289 node -> impl -> options = rcl_node_get_default_options ();
288290 node -> context = context ;
289291 // Initialize node impl.
@@ -319,6 +321,9 @@ rcl_node_init(
319321 local_namespace_ = remapped_namespace ;
320322 }
321323
324+ // compute fully qualified name of the node
325+ node -> impl -> fq_name = rcutils_format_string (* allocator , "%s/%s" , local_namespace_ , name );
326+
322327 // node logger name
323328 node -> impl -> logger_name = rcl_create_node_logger_name (name , local_namespace_ , allocator );
324329 RCL_CHECK_FOR_NULL_WITH_MSG (
@@ -440,6 +445,9 @@ rcl_node_init(
440445 ROS_PACKAGE_NAME , "Failed to fini publisher for node: %i" , ret );
441446 allocator -> deallocate ((char * )node -> impl -> logger_name , allocator -> state );
442447 }
448+ if (node -> impl -> fq_name ) {
449+ allocator -> deallocate ((char * )node -> impl -> fq_name , allocator -> state );
450+ }
443451 if (node -> impl -> rmw_node_handle ) {
444452 ret = rmw_destroy_node (node -> impl -> rmw_node_handle );
445453 if (ret != RMW_RET_OK ) {
@@ -514,6 +522,7 @@ rcl_node_fini(rcl_node_t * node)
514522 allocator .deallocate (node -> impl -> graph_guard_condition , allocator .state );
515523 // assuming that allocate and deallocate are ok since they are checked in init
516524 allocator .deallocate ((char * )node -> impl -> logger_name , allocator .state );
525+ allocator .deallocate ((char * )node -> impl -> fq_name , allocator .state );
517526 if (NULL != node -> impl -> options .arguments .impl ) {
518527 rcl_ret_t ret = rcl_arguments_fini (& (node -> impl -> options .arguments ));
519528 if (ret != RCL_RET_OK ) {
@@ -609,23 +618,7 @@ rcl_node_get_fully_qualified_name(const rcl_node_t * node)
609618 if (!rcl_node_is_valid_except_context (node )) {
610619 return NULL ; // error already set
611620 }
612-
613- const char * name = rcl_node_get_name (node );
614- const char * ns = rcl_node_get_namespace (node );
615- char * fq_name = NULL ;
616-
617- if ('/' == ns [strlen (ns ) - 1 ]) {
618- fq_name = (char * )calloc (strlen (ns ) + strlen (name ), sizeof (char ));
619- strcpy (fq_name , ns );
620- strcat (fq_name , name );
621- }
622- else {
623- fq_name = (char * )calloc (strlen (ns ) + strlen (name ) + 1 , sizeof (char ));
624- strcpy (fq_name , ns );
625- strcat (fq_name , "/" );
626- strcat (fq_name , name );
627- }
628- return fq_name ;
621+ return node -> impl -> fq_name ;
629622}
630623
631624const rcl_node_options_t *
0 commit comments