From 236ca8fbe84575504f6ae80aec63c8059b875ef0 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 24 Jul 2020 12:26:11 +0200 Subject: Allocator: make leak detection work with static variables When definining static variables that own memory, you should use the "construct on first use" idiom. Otherwise, you'll get a warning when Blender exits. More details are provided in D8354. Differential Revision: https://developer.blender.org/D8354 --- tests/gtests/blenloader/blendfile_loading_base_test.cc | 8 -------- tests/gtests/testing/CMakeLists.txt | 2 ++ tests/gtests/testing/testing_main.cc | 3 +++ 3 files changed, 5 insertions(+), 8 deletions(-) (limited to 'tests/gtests') diff --git a/tests/gtests/blenloader/blendfile_loading_base_test.cc b/tests/gtests/blenloader/blendfile_loading_base_test.cc index f15ae615e8a..1f3a312de5d 100644 --- a/tests/gtests/blenloader/blendfile_loading_base_test.cc +++ b/tests/gtests/blenloader/blendfile_loading_base_test.cc @@ -100,14 +100,6 @@ void BlendfileLoadingBaseTest::TearDownTestCase() BKE_blender_atexit(); - if (MEM_get_memory_blocks_in_use() != 0) { - size_t mem_in_use = MEM_get_memory_in_use() + MEM_get_memory_in_use(); - printf("Error: Not freed memory blocks: %u, total unfreed memory %f MB\n", - MEM_get_memory_blocks_in_use(), - (double)mem_in_use / 1024 / 1024); - MEM_printmemlist(); - } - BKE_tempdir_session_purge(); testing::Test::TearDownTestCase(); diff --git a/tests/gtests/testing/CMakeLists.txt b/tests/gtests/testing/CMakeLists.txt index c8a7f487c5d..d557b27f272 100644 --- a/tests/gtests/testing/CMakeLists.txt +++ b/tests/gtests/testing/CMakeLists.txt @@ -28,6 +28,7 @@ set(INC ${GLOG_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS} ../../../extern/gtest/include + ../../../intern/guardedalloc ) set(INC_SYS @@ -40,6 +41,7 @@ set(SRC ) set(LIB + bf_intern_guardedalloc ) blender_add_lib(bf_testing_main "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/tests/gtests/testing/testing_main.cc b/tests/gtests/testing/testing_main.cc index 0acdcf3a8a5..9816e71526b 100644 --- a/tests/gtests/testing/testing_main.cc +++ b/tests/gtests/testing/testing_main.cc @@ -19,6 +19,8 @@ #include "testing/testing.h" +#include "MEM_guardedalloc.h" + DEFINE_string(test_assets_dir, "", "lib/tests directory from SVN containing the test assets."); DEFINE_string(test_release_dir, "", "bin/{blender version} directory of the current build."); @@ -46,6 +48,7 @@ const std::string &flags_test_release_dir() int main(int argc, char **argv) { + MEM_initialize_memleak_detection(); testing::InitGoogleTest(&argc, argv); BLENDER_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); -- cgit v1.2.3