diff --git a/src/mpi/c/comm_create_errhandler.c b/src/mpi/c/comm_create_errhandler.c index 333977402c..eda214484e 100644 --- a/src/mpi/c/comm_create_errhandler.c +++ b/src/mpi/c/comm_create_errhandler.c @@ -29,13 +29,14 @@ int MPI_Comm_create_errhandler(MPI_Comm_errhandler_fn *function, } } - /* Create and cache the errhandler */ + /* Create and cache the errhandler. Sets a refcount of 1. */ *errhandler = lam_errhandler_create(LAM_ERRHANDLER_TYPE_COMM, (lam_errhandler_fortran_handler_fn_t*) function); - if (NULL == *errhandler) + if (NULL == *errhandler) { err = MPI_ERR_INTERN; + } LAM_ERRHANDLER_RETURN(err, MPI_COMM_WORLD, MPI_ERR_INTERN, "MPI_Comm_create_errhandler"); diff --git a/src/mpi/c/comm_get_errhandler.c b/src/mpi/c/comm_get_errhandler.c index e9533e0eea..ba521f2947 100644 --- a/src/mpi/c/comm_get_errhandler.c +++ b/src/mpi/c/comm_get_errhandler.c @@ -29,7 +29,8 @@ int MPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler *errhandler) } } - /* Return the errhandler */ + /* Return the errhandler. Do not increase the refcount here; we + only refcount on communicators */ *errhandler = comm->error_handler; diff --git a/src/mpi/c/comm_set_errhandler.c b/src/mpi/c/comm_set_errhandler.c index fa75816158..f2cf848803 100644 --- a/src/mpi/c/comm_set_errhandler.c +++ b/src/mpi/c/comm_set_errhandler.c @@ -31,11 +31,11 @@ int MPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) } } - /* Ditch the old errhandler */ + /* Ditch the old errhandler, and decrement its refcount */ OBJ_RELEASE(comm->error_handler); - /* We have a valid comm and errhandler */ + /* We have a valid comm and errhandler, so increment its refcount */ comm->error_handler = errhandler; OBJ_RETAIN(comm->error_handler);