From 69d96f808107fa18e4d2ee49b058dfa324dae506 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Mon, 30 May 2022 15:55:14 -0400 Subject: [PATCH] Fix: trace-ir.hpp: spurious reference on object creation 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 Change-Id: Idfe8184497a00d3192e390017d7717c7ff9a3344 Reviewed-on: https://review.lttng.org/c/babeltrace/+/8187 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/10830 Tested-by: jenkins CI-Build: Philippe Proulx --- src/cpp-common/bt2/trace-ir.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cpp-common/bt2/trace-ir.hpp b/src/cpp-common/bt2/trace-ir.hpp index 727a9946..a7576a56 100644 --- a/src/cpp-common/bt2/trace-ir.hpp +++ b/src/cpp-common/bt2/trace-ir.hpp @@ -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::Shared _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) { static_assert(!std::is_const::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); } }; -- 2.34.1