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 <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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)
"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