Skip to content

Commit

Permalink
Add parentheses to fix dereferencing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ilumsden committed Nov 3, 2023
1 parent f5776eb commit 7b48c7a
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/core/dyad_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ DYAD_CORE_FUNC_MODS dyad_rc_t dyad_kvs_read (const dyad_ctx_t* restrict ctx,
}
}
size_t topic_len = strlen (topic);
*mdata->fpath = (char*)malloc (topic_len + 1);
if (*mdata->fpath == NULL) {
(*mdata)->fpath = (char*)malloc (topic_len + 1);
if ((*mdata)->fpath == NULL) {
DYAD_LOG_ERR (ctx, "Cannot allocate memory for fpath in metadata object");
rc = DYAD_RC_SYSFAIL;
goto kvs_read_end;
}
memset (*mdata->fpath, '\0', topic_len + 1);
strncpy (*mdata->fpath, topic, topic_len);
memset ((*mdata)->fpath, '\0', topic_len + 1);
strncpy ((*mdata)->fpath, topic, topic_len);
rc = flux_kvs_lookup_get_unpack (f, "i", &((*mdata)->owner_rank));
// If the extraction did not work, log an error and return DYAD_BADFETCH
if (rc < 0) {
Expand All @@ -243,8 +243,8 @@ DYAD_CORE_FUNC_MODS dyad_rc_t dyad_kvs_read (const dyad_ctx_t* restrict ctx,

kvs_read_end:
if (DYAD_IS_ERROR (rc) && mdata != NULL && *mdata != NULL) {
if (*mdata->fpath != NULL)
free (*mdata->fpath);
if ((*mdata)->fpath != NULL)
free ((*mdata)->fpath);
free (*mdata);
*mdata = NULL;
}
Expand All @@ -257,7 +257,7 @@ DYAD_CORE_FUNC_MODS dyad_rc_t dyad_kvs_read (const dyad_ctx_t* restrict ctx,

DYAD_CORE_FUNC_MODS dyad_rc_t dyad_fetch (const dyad_ctx_t* restrict ctx,
const char* restrict fname,
dyad_mdata_t** restrict mdata)
dyad_metadata_t** restrict mdata)
{
dyad_rc_t rc = DYAD_RC_OK;
char upath[PATH_MAX];
Expand Down Expand Up @@ -301,8 +301,8 @@ DYAD_CORE_FUNC_MODS dyad_rc_t dyad_fetch (const dyad_ctx_t* restrict ctx,
"same as the consumer rank\n");
*resp = NULL;
if (mdata != NULL && *mdata != NULL) {
if (*mdata->fpath != NULL)
free (*mdata->fpath);
if ((*mdata)->fpath != NULL)
free ((*mdata)->fpath);
free (*mdata);
*mdata = NULL;
}
Expand Down Expand Up @@ -769,22 +769,22 @@ dyad_rc_t dyad_get_metadata (dyad_ctx_t* ctx,
DYAD_LOG_ERR (ctx, "Could not read data from the KVS");
goto get_metadata_done;
}
free (*mdata->fpath);
free ((*mdata)->fpath);
size_t fname_len = strlen (fname);
*mdata->fpath = (char*)malloc (fname_len + 1);
if (*mdata->fpath == NULL) {
(*mdata)->fpath = (char*)malloc (fname_len + 1);
if ((*mdata)->fpath == NULL) {
DYAD_LOG_ERR (ctx, "Could not allocate memory for fpath");
rc = DYAD_RC_SYSFAIL;
goto get_metadata_done;
}
memset (*mdata->fpath, '\0', fname_len + 1);
strncpy (*mdata->fpath, fname, fname_len);
memset ((*mdata)->fpath, '\0', fname_len + 1);
strncpy ((*mdata)->fpath, fname, fname_len);
rc = DYAD_RC_OK;

get_metadata_done:
if (DYAD_IS_ERROR (rc) && mdata != NULL && *mdata != NULL) {
if (*mdata->fpath != NULL)
free (*mdata->fpath);
if ((*mdata)->fpath != NULL)
free ((*mdata)->fpath);
free (*mdata);
*mdata = NULL;
}
Expand Down

0 comments on commit 7b48c7a

Please sign in to comment.