Yield rcl_context_fini() error codes. (#763)

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
This commit is contained in:
Michel Hidalgo 2020-08-25 17:23:47 -03:00 committed by Alejandro Hernández Cordero
parent 4476c92dd4
commit 13ded97050
2 changed files with 18 additions and 9 deletions

View file

@ -21,6 +21,7 @@ extern "C"
#include <stdbool.h>
#include "./common.h"
#include "./context_impl.h"
#include "rcutils/stdatomic_helper.h"
@ -56,8 +57,7 @@ rcl_context_fini(rcl_context_t * context)
}
RCL_CHECK_ALLOCATOR_WITH_MSG(
&(context->impl->allocator), "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
__cleanup_context(context);
return RCL_RET_OK;
return __cleanup_context(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);
}
void
rcl_ret_t
__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)
rcutils_atomic_store((atomic_uint_least64_t *)(&context->instance_id_storage), 0);
// clean up global_arguments if initialized
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) {
RCUTILS_SAFE_FWRITE_TO_STDERR(
"[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
@ -118,8 +119,11 @@ __cleanup_context(rcl_context_t * context)
// finalize init options if valid
if (NULL != context->impl->init_options.impl) {
rcl_ret_t ret = rcl_init_options_fini(&(context->impl->init_options));
if (RCL_RET_OK != ret) {
rcl_ret_t init_options_fini_ret = rcl_init_options_fini(&(context->impl->init_options));
if (RCL_RET_OK != init_options_fini_ret) {
if (RCL_RET_OK == ret) {
ret = init_options_fini_ret;
}
RCUTILS_SAFE_FWRITE_TO_STDERR(
"[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
"] 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
if (NULL != context->impl->rmw_context.implementation_identifier) {
rmw_ret_t rmw_ret = rmw_context_fini(&(context->impl->rmw_context));
if (RMW_RET_OK != rmw_ret) {
rmw_ret_t rmw_context_fini_ret = rmw_context_fini(&(context->impl->rmw_context));
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(
"[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
"] 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
*context = rcl_get_zero_initialized_context();
return ret;
}
#ifdef __cplusplus

View file

@ -41,7 +41,7 @@ typedef struct rcl_context_impl_t
} rcl_context_impl_t;
RCL_LOCAL
void
rcl_ret_t
__cleanup_context(rcl_context_t * context);
#ifdef __cplusplus