ctf: use unique_ptr to manage ctf_metadata_decoder lifetime
[babeltrace.git] / src / plugins / ctf / fs-src / query.cpp
index 95453ada5595eb4db7a10228bfcf95bc6135b10f..6625ec7d403e7fdbd1bd6508b253d1ff47d76372 100644 (file)
@@ -39,7 +39,7 @@ bt_component_class_query_method_status metadata_info_query(const bt_value *param
     int bo;
     const char *path;
     bool is_packetized;
-    struct ctf_metadata_decoder *decoder = NULL;
+    ctf_metadata_decoder_up decoder;
     ctf_metadata_decoder_config decoder_cfg {logger};
     enum ctf_metadata_decoder_status decoder_status;
     GString *g_metadata_text = NULL;
@@ -97,14 +97,14 @@ bt_component_class_query_method_status metadata_info_query(const bt_value *param
     }
 
     rewind(metadata_fp.get());
-    decoder_status = ctf_metadata_decoder_append_content(decoder, metadata_fp.get());
+    decoder_status = ctf_metadata_decoder_append_content(decoder.get(), metadata_fp.get());
     if (decoder_status) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(
             logger, "Cannot update metadata decoder's content: path=\"{}\".", path);
         goto error;
     }
 
-    plaintext = ctf_metadata_decoder_get_text(decoder);
+    plaintext = ctf_metadata_decoder_get_text(decoder.get());
     g_metadata_text = g_string_new(NULL);
 
     if (!g_metadata_text) {
@@ -117,7 +117,6 @@ bt_component_class_query_method_status metadata_info_query(const bt_value *param
     }
 
     g_string_append(g_metadata_text, plaintext);
-
     ret = bt_value_map_insert_string_entry(result, "text", g_metadata_text->str);
     if (ret) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot insert metadata text into query result.");
@@ -145,7 +144,6 @@ end:
     if (g_metadata_text) {
         g_string_free(g_metadata_text, TRUE);
     }
-    ctf_metadata_decoder_destroy(decoder);
 
     *user_result = result;
     return status;
@@ -364,7 +362,7 @@ support_info_query(const bt_value *params, const bt2c::Logger& logger, const bt_
     double weight = 0;
     bt2c::GCharUP metadata_path;
     bt_value *result = NULL;
-    struct ctf_metadata_decoder *metadata_decoder = NULL;
+    ctf_metadata_decoder_up metadata_decoder;
     FILE *metadata_file = NULL;
     char uuid_str[BT_UUID_STR_LEN + 1];
     bool has_uuid = false;
@@ -404,7 +402,7 @@ support_info_query(const bt_value *params, const bt2c::Logger& logger, const bt_
             goto end;
         }
 
-        decoder_status = ctf_metadata_decoder_append_content(metadata_decoder, metadata_file);
+        decoder_status = ctf_metadata_decoder_append_content(metadata_decoder.get(), metadata_file);
         if (decoder_status != CTF_METADATA_DECODER_STATUS_OK) {
             BT_CPPLOGW_SPEC(logger, "cannot append metadata content: metadata-decoder-status={}",
                             decoder_status);
@@ -419,7 +417,7 @@ support_info_query(const bt_value *params, const bt2c::Logger& logger, const bt_
         weight = 0.75;
 
         /* If the trace has a UUID, return the stringified UUID as the group. */
-        if (ctf_metadata_decoder_get_trace_class_uuid(metadata_decoder, uuid) == 0) {
+        if (ctf_metadata_decoder_get_trace_class_uuid(metadata_decoder.get(), uuid) == 0) {
             bt_uuid_to_str(uuid, uuid_str);
             has_uuid = true;
         }
@@ -455,7 +453,6 @@ create_result:
 
 end:
     bt_value_put_ref(result);
-    ctf_metadata_decoder_destroy(metadata_decoder);
 
     return status;
 }
This page took 0.024404 seconds and 4 git commands to generate.