diff --git a/src/fmpi_ctx.c b/src/fmpi_ctx.c index e265efe1c7881e64dd09bd46b29f4cb354ce28b7..6d9a338cc7b10cd81306973ce35f494f24ad16ac 100644 --- a/src/fmpi_ctx.c +++ b/src/fmpi_ctx.c @@ -74,8 +74,10 @@ struct fmpi_ctx * fmpi_ctx_create(int * const argc, char ** argv[]) .user_data = ctx }); if(ctx->mpi == NULL) { - FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_mpi_init() failed!"); - fmpi_ctx_destroy(&ctx); + FMPI_RAISE_ERROR(err_handler, "FMPI", "fmpi_mpi_init() failed!"); + if(fmpi_ctx_destroy(&ctx) != FMPI_SUCCESS) { + FMPI_RAISE_ERROR(err_handler, "FMPI", "fmpi_ctx_destroy() failed!"); + } return NULL; } // Futhark Initialization @@ -84,8 +86,11 @@ struct fmpi_ctx * fmpi_ctx_create(int * const argc, char ** argv[]) .user_data = ctx }); if(ctx->fut == NULL) { - FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_futhark_init() failed!"); - fmpi_ctx_destroy(&ctx); + FMPI_RAISE_ERROR(err_handler, "FMPI", "fmpi_futhark_init() failed!"); + if(fmpi_ctx_destroy(&ctx) != FMPI_SUCCESS) { + FMPI_RAISE_ERROR(err_handler, "FMPI", "fmpi_ctx_destroy() failed!"); + } + return NULL; } return ctx; } @@ -97,15 +102,17 @@ int fmpi_ctx_destroy(struct fmpi_ctx ** const ctx) assert(ctx != NULL); assert(*ctx != NULL); - int err_id = -1; - if((*ctx)->fut != NULL) { - err_id = fmpi_futhark_exit(&(*ctx)->fut); + int err = FMPI_SUCCESS; + if((*ctx)->fut != NULL && fmpi_futhark_exit(&(*ctx)->fut) != FMPI_SUCCESS) { + FMPI_RAISE_ERROR((*ctx)->err_handler, "FMPI", "fmpi_futhark_exit() failed!"); + err = FMPI_ERROR; } - if((*ctx)->mpi != NULL) { - err_id = fmpi_mpi_exit(&(*ctx)->mpi); + if((*ctx)->mpi != NULL && fmpi_mpi_exit(&(*ctx)->mpi) != FMPI_SUCCESS) { + FMPI_RAISE_ERROR((*ctx)->err_handler, "FMPI", "fmpi_mpi_exit() failed!"); + err = FMPI_ERROR; } free(*ctx); *ctx = NULL; - return err_id; + return err; } /*============================================================================== PRIVATE FUNCTION DEFINITION