From: Simon Marchi Date: Thu, 6 Jan 2022 18:27:55 +0000 (-0500) Subject: lttng-sessiond: remove goto in ust_metadata_channel_statedump X-Git-Url: https://git.lttng.org/?a=commitdiff_plain;h=e4589ae2396a53ed0b17251616694afeefba2986;hp=0d19be9d7e89fa4ff548592edd6d00a723070ced;p=lttng-tools.git lttng-sessiond: remove goto in ust_metadata_channel_statedump A follow-up patch uses an std::vector declared in the middle of ust_metadata_channel_statedump. This isn't compatible with the goto-based error handling, since gotos should not jump over object initialization (otherwise, the object gets destroyed without having been constructed). Moving the std::vector declaration to the beginning of the function would work, but it would be a pessimization: we would construct an object that we may not need, depending on the code path taken. We therefore want to declare (and construct) the std::vector just before we need it. Fix this by replacing gotos with return statements. Also, add a `ret` check after the last lttng_metadata_printf call. If this call failed, for some reason, we would return an error, but still set chan->metadata_dumped. That makes this case different than the other error paths in the function, where chan->metadata_dumped doesn't get set. Adding the check makes this case like the other ones. Change-Id: Iba81422a7c3bac96a8d209bba6b4d53ad26b3e4e Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/ust-metadata.cpp b/src/bin/lttng-sessiond/ust-metadata.cpp index b507f7870..d08cb40ae 100644 --- a/src/bin/lttng-sessiond/ust-metadata.cpp +++ b/src/bin/lttng-sessiond/ust-metadata.cpp @@ -899,7 +899,7 @@ end: int ust_metadata_channel_statedump(struct ust_registry_session *session, struct ust_registry_channel *chan) { - int ret = 0; + int ret; /* Don't dump metadata events */ if (chan->chan_id == -1U) @@ -918,37 +918,40 @@ int ust_metadata_channel_statedump(struct ust_registry_session *session, "struct event_header_compact" : "struct event_header_large"); if (ret) { - goto end; + return ret; } if (chan->ctx_fields) { ret = lttng_metadata_printf(session, " event.context := struct {\n"); if (ret) { - goto end; + return ret; } } ret = _lttng_context_metadata_statedump(session, chan->nr_ctx_fields, chan->ctx_fields); if (ret) { - goto end; + return ret; } if (chan->ctx_fields) { ret = lttng_metadata_printf(session, " };\n"); if (ret) { - goto end; + return ret; } } ret = lttng_metadata_printf(session, "};\n\n"); + if (ret) { + return ret; + } + /* Flag success of metadata dump. */ chan->metadata_dumped = 1; -end: - return ret; + return 0; } static