[Bf-blender-cvs] [b3283176a0e] functions: fix memory leaks in unit tests
Jacques Lucke
noreply at git.blender.org
Wed May 22 17:32:29 CEST 2019
Commit: b3283176a0e48c9f152236fe5da0a52d8f7aaadc
Author: Jacques Lucke
Date: Wed May 22 16:05:01 2019 +0200
Branches: functions
https://developer.blender.org/rBb3283176a0e48c9f152236fe5da0a52d8f7aaadc
fix memory leaks in unit tests
===================================================================
M source/blender/blenlib/BLI_optional.hpp
M tests/gtests/blenlib/BLI_shared_test.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_optional.hpp b/source/blender/blenlib/BLI_optional.hpp
index c1ee980577e..a845ce270f1 100644
--- a/source/blender/blenlib/BLI_optional.hpp
+++ b/source/blender/blenlib/BLI_optional.hpp
@@ -46,24 +46,18 @@ template<typename T> class Optional {
this->set(value);
}
- Optional(const Optional &other)
+ Optional(const Optional &other) : Optional()
{
if (other.has_value()) {
this->set(other.value());
}
- else {
- m_set = false;
- }
}
- Optional(Optional &&other)
+ Optional(Optional &&other) : Optional()
{
if (other.has_value()) {
this->set(std::move(other.value()));
}
- else {
- m_set = false;
- }
}
Optional &operator=(const Optional &other)
diff --git a/tests/gtests/blenlib/BLI_shared_test.cc b/tests/gtests/blenlib/BLI_shared_test.cc
index 0d9e8e55b61..b4d3fc170fa 100644
--- a/tests/gtests/blenlib/BLI_shared_test.cc
+++ b/tests/gtests/blenlib/BLI_shared_test.cc
@@ -95,6 +95,8 @@ TEST(shared, CustomIncRef)
ASSERT_EQ(ptr->refcount(), 1);
ptr->incref();
ASSERT_EQ(ptr->refcount(), 2);
+ ptr->decref();
+ ptr->decref();
}
TEST(shared, CustomDecRef)
@@ -104,6 +106,7 @@ TEST(shared, CustomDecRef)
ASSERT_EQ(ptr->refcount(), 2);
ptr->decref();
ASSERT_EQ(ptr->refcount(), 1);
+ ptr->decref();
}
TEST(shared, ExtractRefCounted)
@@ -113,6 +116,7 @@ TEST(shared, ExtractRefCounted)
ASSERT_EQ(obj->refcount(), 1);
ptr->incref();
ASSERT_EQ(obj->refcount(), 2);
+ ptr->decref();
}
TEST(shared, DecRefToZero)
@@ -122,4 +126,4 @@ TEST(shared, DecRefToZero)
ASSERT_TRUE(alive);
ptr->decref();
ASSERT_FALSE(alive);
-}
\ No newline at end of file
+}
More information about the Bf-blender-cvs
mailing list