Fix: trace-ir.hpp: spurious reference on object creation
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Mon, 30 May 2022 19:55:14 +0000 (15:55 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Sep 2023 15:24:02 +0000 (11:24 -0400)
We create a variant field class, which initially has refcount == 1.  We
then call `.shared()`, which creates another reference, bringing the
refcount to 2.

Fix that by using the `Shared::createWithoutRef()` method.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Idfe8184497a00d3192e390017d7717c7ff9a3344
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8187
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10830
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

src/cpp-common/bt2/trace-ir.hpp

index 727a9946c11e81ccab4bfdd18e22fb12642f06e1..a7576a56ce62607a6c39c01fa4249b30a999feeb 100644 (file)
@@ -2185,17 +2185,15 @@ public:
     VariantWithUnsignedIntegerSelectorFieldClass::Shared
     createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
     {
-        return VariantWithUnsignedIntegerSelectorFieldClass {
-            this->_createVariantWithIntegerSelectorFieldClass(selectorFieldClass)}
-            .shared();
+        return this->_createVariantWithIntegerSelectorFieldClass<
+            VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
     }
 
     VariantWithSignedIntegerSelectorFieldClass::Shared
     createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
     {
-        return VariantWithSignedIntegerSelectorFieldClass {
-            this->_createVariantWithIntegerSelectorFieldClass(selectorFieldClass)}
-            .shared();
+        return this->_createVariantWithIntegerSelectorFieldClass<
+            VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
     }
 
     void assignsAutomaticStreamClassId(const bool val) noexcept
@@ -2273,7 +2271,8 @@ public:
     }
 
 private:
-    bt_field_class *
+    template <typename ObjT>
+    typename ObjT::Shared
     _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
@@ -2282,7 +2281,7 @@ private:
             bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return libObjPtr;
+        return ObjT::Shared::createWithoutRef(libObjPtr);
     }
 };
 
This page took 0.025213 seconds and 4 git commands to generate.