Skip to content

Commit

Permalink
modules/kvs: Cleanup asprintf error paths
Browse files Browse the repository at this point in the history
asprintf already sets errno on error, so there is no need to explicitly
set errno = ENOMEM on asprintf errors.
  • Loading branch information
chu11 committed Feb 26, 2020
1 parent 2647165 commit ccd3865
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions src/modules/kvs/kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,30 +211,24 @@ static int event_subscribe (kvs_ctx_t *ctx, const char *ns)
}

if (ctx->rank != 0) {
if (asprintf (&setroot_topic, "kvs.setroot-%s", ns) < 0) {
errno = ENOMEM;
if (asprintf (&setroot_topic, "kvs.setroot-%s", ns) < 0)
goto cleanup;
}

if (flux_event_subscribe (ctx->h, setroot_topic) < 0) {
flux_log_error (ctx->h, "flux_event_subscribe");
goto cleanup;
}

if (asprintf (&error_topic, "kvs.error-%s", ns) < 0) {
errno = ENOMEM;
if (asprintf (&error_topic, "kvs.error-%s", ns) < 0)
goto cleanup;
}

if (flux_event_subscribe (ctx->h, error_topic) < 0) {
flux_log_error (ctx->h, "flux_event_subscribe");
goto cleanup;
}

if (asprintf (&removed_topic, "kvs.namespace-removed-%s", ns) < 0) {
errno = ENOMEM;
if (asprintf (&removed_topic, "kvs.namespace-removed-%s", ns) < 0)
goto cleanup;
}

if (flux_event_subscribe (ctx->h, removed_topic) < 0) {
flux_log_error (ctx->h, "flux_event_subscribe");
Expand All @@ -258,30 +252,24 @@ static int event_unsubscribe (kvs_ctx_t *ctx, const char *ns)
int rc = -1;

if (ctx->rank != 0) {
if (asprintf (&setroot_topic, "kvs.setroot-%s", ns) < 0) {
errno = ENOMEM;
if (asprintf (&setroot_topic, "kvs.setroot-%s", ns) < 0)
goto cleanup;
}

if (flux_event_unsubscribe (ctx->h, setroot_topic) < 0) {
flux_log_error (ctx->h, "flux_event_subscribe");
goto cleanup;
}

if (asprintf (&error_topic, "kvs.error-%s", ns) < 0) {
errno = ENOMEM;
if (asprintf (&error_topic, "kvs.error-%s", ns) < 0)
goto cleanup;
}

if (flux_event_unsubscribe (ctx->h, error_topic) < 0) {
flux_log_error (ctx->h, "flux_event_subscribe");
goto cleanup;
}

if (asprintf (&removed_topic, "kvs.namespace-removed-%s", ns) < 0) {
errno = ENOMEM;
if (asprintf (&removed_topic, "kvs.namespace-removed-%s", ns) < 0)
goto cleanup;
}

if (flux_event_subscribe (ctx->h, removed_topic) < 0) {
flux_log_error (ctx->h, "flux_event_subscribe");
Expand Down Expand Up @@ -2423,10 +2411,8 @@ static int namespace_create (kvs_ctx_t *ctx, const char *ns,
goto cleanup;
}

if (asprintf (&topic, "kvs.namespace-created-%s", ns) < 0) {
errno = ENOMEM;
if (asprintf (&topic, "kvs.namespace-created-%s", ns) < 0)
goto cleanup;
}

if (!(msg = flux_event_pack (topic,
"{ s:s s:i s:s s:i }",
Expand Down

0 comments on commit ccd3865

Please sign in to comment.