Skip to content

Commit

Permalink
Fixes a bug in dyad_dtl_finalize that could cause the dtl handle to n…
Browse files Browse the repository at this point in the history
…ot be freed in some cases
  • Loading branch information
ilumsden committed Oct 30, 2023
1 parent e86723a commit 6890cd9
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/dtl/dyad_dtl_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,51 @@ dyad_rc_t dyad_dtl_init (dyad_dtl_t **dtl_handle,
dyad_rc_t rc = DYAD_RC_OK;
*dtl_handle = malloc (sizeof (struct dyad_dtl));
if (*dtl_handle == NULL) {
return DYAD_RC_SYSFAIL;
rc = DYAD_RC_SYSFAIL;
goto dtl_init_done;
}
(*dtl_handle)->mode = mode;
#if DYAD_ENABLE_UCX
if (mode == DYAD_DTL_UCX) {
rc = dyad_dtl_ucx_init (*dtl_handle, mode, h, debug);
if (DYAD_IS_ERROR (rc)) {
return rc;
goto dtl_init_done;
}
return DYAD_RC_OK;
} else if (mode == DYAD_DTL_FLUX_RPC) {
#else
if (mode == DYAD_DTL_FLUX_RPC) {
#endif
rc = dyad_dtl_flux_init (*dtl_handle, mode, h, debug);
if (DYAD_IS_ERROR (rc)) {
return rc;
goto dtl_init_done;
}
return DYAD_RC_OK;
} else {
rc = DYAD_RC_BADDTLMODE;
goto dtl_init_done;
}
return DYAD_RC_BADDTLMODE;
rc = DYAD_RC_OK;

dtl_init_done:
return rc;
}

dyad_rc_t dyad_dtl_finalize (dyad_dtl_t **dtl_handle)
{
dyad_rc_t rc = DYAD_RC_OK;
if (dtl_handle == NULL || *dtl_handle == NULL)
if (dtl_handle == NULL || *dtl_handle == NULL) {
// We should only reach this line if the user has passed
// in an already-finalized DTL handle. In that case,
// this function should be treated as a no-op, and we
// should return DYAD_RC_OK to indicate no error has occured
return DYAD_RC_OK;
rc = DYAD_RC_OK;
goto dtl_finalize_done;
}
#if DYAD_ENABLE_UCX
if ((*dtl_handle)->mode == DYAD_DTL_UCX) {
if ((*dtl_handle)->private.ucx_dtl_handle != NULL) {
rc = dyad_dtl_ucx_finalize (dtl_handle);
if (DYAD_IS_ERROR (rc)) {
return rc;
goto dtl_finalize_done;
}
}
} else if ((*dtl_handle)->mode == DYAD_DTL_FLUX_RPC) {
Expand All @@ -61,13 +68,17 @@ dyad_rc_t dyad_dtl_finalize (dyad_dtl_t **dtl_handle)
if ((*dtl_handle)->private.flux_dtl_handle != NULL) {
rc = dyad_dtl_flux_finalize (dtl_handle);
if (DYAD_IS_ERROR (rc)) {
return rc;
goto dtl_finalize_done;
}
}
} else {
return DYAD_RC_BADDTLMODE;
rc = DYAD_RC_BADDTLMODE;
goto dtl_finalize_done;
}
rc = DYAD_RC_OK;

dtl_finalize_done:
free (*dtl_handle);
*dtl_handle = NULL;
return DYAD_RC_OK;
return rc;
}

0 comments on commit 6890cd9

Please sign in to comment.