Yield rcl_context_fini() error codes. (#763)
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
This commit is contained in:
parent
4476c92dd4
commit
13ded97050
2 changed files with 18 additions and 9 deletions
|
@ -21,6 +21,7 @@ extern "C"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "./common.h"
|
||||||
#include "./context_impl.h"
|
#include "./context_impl.h"
|
||||||
#include "rcutils/stdatomic_helper.h"
|
#include "rcutils/stdatomic_helper.h"
|
||||||
|
|
||||||
|
@ -56,8 +57,7 @@ rcl_context_fini(rcl_context_t * context)
|
||||||
}
|
}
|
||||||
RCL_CHECK_ALLOCATOR_WITH_MSG(
|
RCL_CHECK_ALLOCATOR_WITH_MSG(
|
||||||
&(context->impl->allocator), "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
|
&(context->impl->allocator), "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
|
||||||
__cleanup_context(context);
|
return __cleanup_context(context);
|
||||||
return RCL_RET_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// See `rcl_shutdown()` for invalidation of the context.
|
// See `rcl_shutdown()` for invalidation of the context.
|
||||||
|
@ -92,15 +92,16 @@ rcl_context_get_rmw_context(rcl_context_t * context)
|
||||||
return &(context->impl->rmw_context);
|
return &(context->impl->rmw_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
rcl_ret_t
|
||||||
__cleanup_context(rcl_context_t * context)
|
__cleanup_context(rcl_context_t * context)
|
||||||
{
|
{
|
||||||
|
rcl_ret_t ret = RCL_RET_OK;
|
||||||
// reset the instance id to 0 to indicate "invalid" (should already be 0, but this is defensive)
|
// reset the instance id to 0 to indicate "invalid" (should already be 0, but this is defensive)
|
||||||
rcutils_atomic_store((atomic_uint_least64_t *)(&context->instance_id_storage), 0);
|
rcutils_atomic_store((atomic_uint_least64_t *)(&context->instance_id_storage), 0);
|
||||||
|
|
||||||
// clean up global_arguments if initialized
|
// clean up global_arguments if initialized
|
||||||
if (NULL != context->global_arguments.impl) {
|
if (NULL != context->global_arguments.impl) {
|
||||||
rcl_ret_t ret = rcl_arguments_fini(&(context->global_arguments));
|
ret = rcl_arguments_fini(&(context->global_arguments));
|
||||||
if (RCL_RET_OK != ret) {
|
if (RCL_RET_OK != ret) {
|
||||||
RCUTILS_SAFE_FWRITE_TO_STDERR(
|
RCUTILS_SAFE_FWRITE_TO_STDERR(
|
||||||
"[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
|
"[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
|
||||||
|
@ -118,8 +119,11 @@ __cleanup_context(rcl_context_t * context)
|
||||||
|
|
||||||
// finalize init options if valid
|
// finalize init options if valid
|
||||||
if (NULL != context->impl->init_options.impl) {
|
if (NULL != context->impl->init_options.impl) {
|
||||||
rcl_ret_t ret = rcl_init_options_fini(&(context->impl->init_options));
|
rcl_ret_t init_options_fini_ret = rcl_init_options_fini(&(context->impl->init_options));
|
||||||
if (RCL_RET_OK != ret) {
|
if (RCL_RET_OK != init_options_fini_ret) {
|
||||||
|
if (RCL_RET_OK == ret) {
|
||||||
|
ret = init_options_fini_ret;
|
||||||
|
}
|
||||||
RCUTILS_SAFE_FWRITE_TO_STDERR(
|
RCUTILS_SAFE_FWRITE_TO_STDERR(
|
||||||
"[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
|
"[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
|
||||||
"] failed to finalize init options while cleaning up context, memory may be leaked: ");
|
"] failed to finalize init options while cleaning up context, memory may be leaked: ");
|
||||||
|
@ -131,8 +135,11 @@ __cleanup_context(rcl_context_t * context)
|
||||||
|
|
||||||
// clean up rmw_context
|
// clean up rmw_context
|
||||||
if (NULL != context->impl->rmw_context.implementation_identifier) {
|
if (NULL != context->impl->rmw_context.implementation_identifier) {
|
||||||
rmw_ret_t rmw_ret = rmw_context_fini(&(context->impl->rmw_context));
|
rmw_ret_t rmw_context_fini_ret = rmw_context_fini(&(context->impl->rmw_context));
|
||||||
if (RMW_RET_OK != rmw_ret) {
|
if (RMW_RET_OK != rmw_context_fini_ret) {
|
||||||
|
if (RCL_RET_OK == ret) {
|
||||||
|
ret = rcl_convert_rmw_ret_to_rcl_ret(rmw_context_fini_ret);
|
||||||
|
}
|
||||||
RCUTILS_SAFE_FWRITE_TO_STDERR(
|
RCUTILS_SAFE_FWRITE_TO_STDERR(
|
||||||
"[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
|
"[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
|
||||||
"] failed to finalize rmw context while cleaning up context, memory may be leaked: ");
|
"] failed to finalize rmw context while cleaning up context, memory may be leaked: ");
|
||||||
|
@ -157,6 +164,8 @@ __cleanup_context(rcl_context_t * context)
|
||||||
|
|
||||||
// zero-initialize the context
|
// zero-initialize the context
|
||||||
*context = rcl_get_zero_initialized_context();
|
*context = rcl_get_zero_initialized_context();
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -41,7 +41,7 @@ typedef struct rcl_context_impl_t
|
||||||
} rcl_context_impl_t;
|
} rcl_context_impl_t;
|
||||||
|
|
||||||
RCL_LOCAL
|
RCL_LOCAL
|
||||||
void
|
rcl_ret_t
|
||||||
__cleanup_context(rcl_context_t * context);
|
__cleanup_context(rcl_context_t * context);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue