@@ -280,7 +280,8 @@ int ompi_mpi_errcode_finalize (void)
280280 * we have to free.
281281 */
282282 errc = (ompi_mpi_errcode_t * )opal_pointer_array_get_item (& ompi_mpi_errcodes , i );
283- OBJ_RELEASE (errc );
283+ if (NULL != errc )
284+ OBJ_RELEASE (errc );
284285 }
285286
286287 OBJ_DESTRUCT (& ompi_success );
@@ -440,13 +441,24 @@ int ompi_mpi_errcode_remove(int errnum)
440441 if (OPAL_SUCCESS == ret ) {
441442 if (errnum == ompi_mpi_errcode_lastused ) {
442443 ompi_mpi_errcode_lastused -- ;
444+ ret = ompi_mpi_errcode_lastused ;
443445 }
444446 }
445447 }
446448 }
447449
448450 opal_mutex_unlock (& errcode_lock );
449451
452+ /* Release the object on success */
453+ if (ret >= 0 ) {
454+ OBJ_RELEASE (errcodep );
455+ }
456+
457+ /*
458+ * Return lastused value captured under lock so caller has
459+ * consistent value to set MPI_LASTUSEDCODE attribute.
460+ * On error, we return less than zero (e.g., OMPI_ERROR).
461+ */
450462 return ret ;
451463}
452464
@@ -472,6 +484,7 @@ int ompi_mpi_errclass_remove(int errclass)
472484 if (OPAL_SUCCESS == ret ) {
473485 if (errclass == ompi_mpi_errcode_lastused ) {
474486 ompi_mpi_errcode_lastused -- ;
487+ ret = ompi_mpi_errcode_lastused ;
475488 }
476489 }
477490 }
@@ -480,6 +493,16 @@ int ompi_mpi_errclass_remove(int errclass)
480493
481494 opal_mutex_unlock (& errcode_lock );
482495
496+ /* Release the object on success */
497+ if (ret >= 0 ) {
498+ OBJ_RELEASE (errcodep );
499+ }
500+
501+ /*
502+ * Return lastused value captured under lock so caller has
503+ * consistent value to set MPI_LASTUSEDCODE attribute.
504+ * On error, we return less than zero (e.g., OMPI_ERROR).
505+ */
483506 return ret ;
484507}
485508
0 commit comments