Fix: bt2: autodisc: remove thread error while inserting status in map
[babeltrace.git] / src / bindings / python / bt2 / bt2 / native_bt_autodisc.i.h
index 43e9dc82e534f6e244c6b04c89b1c6f48e14f840..d6a4d24bbe1ae0d3f089ee6639ac8ca081111d43 100644 (file)
@@ -43,6 +43,7 @@ bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs,
        bt_value *components_list = NULL;
        bt_value *component_info = NULL;
        bt_value_map_insert_entry_status insert_entry_status;
+       const bt_error *error = NULL;
 
        BT_ASSERT(bt_value_get_type(inputs) == BT_VALUE_TYPE_ARRAY);
        for (i = 0; i < bt_value_array_get_length(inputs); i++) {
@@ -178,11 +179,23 @@ error:
 
 end:
        if (result) {
+               /*
+                * If an error happened, we must clear the error temporarily
+                * while we insert the status in the map.
+                */
+               error = bt_current_thread_take_error();
                insert_entry_status = bt_value_map_insert_signed_integer_entry(result, "status", status);
-               if (insert_entry_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
+               if (insert_entry_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
+                       if (error) {
+                               bt_current_thread_move_error(error);
+                               error = NULL;
+                       }
+               } else {
                        BT_VALUE_PUT_REF_AND_RESET(result);
                        PyErr_NoMemory();
                }
+
+
        }
 
        auto_source_discovery_fini(&auto_disc);
@@ -190,5 +203,9 @@ end:
        bt_value_put_ref(components_list);
        bt_value_put_ref(component_info);
 
+       if (error) {
+               bt_error_release(error);
+       }
+
        return result;
 }
This page took 0.023988 seconds and 4 git commands to generate.