From 3c96d5e0d568408e0505841af39aa2d539ebaf36 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Mon, 3 Jul 2023 20:04:24 -0700 Subject: [PATCH] fix: memory leaks in tests Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- CMakeLists.txt | 15 ++++++++++++--- tests/Task_test.cpp | 1 + tests/Version_test.cpp | 25 +++++++++++++++---------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11e4c6286..bb9906691 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,16 +91,25 @@ option(DEBUG_ADDRESS_SANITIZER "Enable Address Sanitizer in Debug builds" on) if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND DEBUG_ADDRESS_SANITIZER) message(STATUS "Address Sanitizer enabeled for Debug builds, Turn it off with -DDEBUG_ADDRESS_SANITIZER=off") if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - # AppleClang and Clang - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -faddress-sanitizer -O1 -fno-omit-frame-pointer") + if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + # using clang with clang-cl front end + message(STATUS "Address Sanitizer available on Clang MSVC frontend") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address /O1 /Oy-") + else() + # AppleClang and Clang + message(STATUS "Address Sanitizer available on Clang") + set(cmake_cxx_flags "${cmake_cxx_flags} -fsanitize=address -O1 -fno-omit-frame-pointer") + endif() elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -O1 -fno-omit-frame-pointer") + message(STATUS "Address Sanitizer available on GCC") + set(cmake_cxx_flags "${cmake_cxx_flags} -fsanitize=address -O1 -fno-omit-frame-pointer") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") # Intell compiler ? why? # no address sanitiser here though message(STATUS "Address Sanitizer not available on Intell compilers") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + message(STATUS "Address Sanitizer available on MSVC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address /O1 /Oy-") else() message(STATUS "Address Sanitizer not available on unknown compiler ${CMAKE_CXX_COMPILER_ID}") diff --git a/tests/Task_test.cpp b/tests/Task_test.cpp index dabe5da26..a57102d6d 100644 --- a/tests/Task_test.cpp +++ b/tests/Task_test.cpp @@ -80,6 +80,7 @@ class BigConcurrentTaskThread : public QThread { QCoreApplication::processEvents(); emit finished(); + delete[] sub_tasks; } public: diff --git a/tests/Version_test.cpp b/tests/Version_test.cpp index afb4c6102..0f8c1652d 100644 --- a/tests/Version_test.cpp +++ b/tests/Version_test.cpp @@ -20,6 +20,8 @@ class VersionTest : public QObject { Q_OBJECT + QStringList m_flex_test_names = {}; + void addDataColumns() { QTest::addColumn("first"); @@ -101,8 +103,9 @@ class VersionTest : public QObject { QString first{split_line.first().simplified()}; QString second{split_line.last().simplified()}; - auto new_test_name = test_name_template.arg(QString::number(test_number), "lessThan").toLatin1().data(); - QTest::newRow(new_test_name) << first << second << true << false; + auto new_test_name = test_name_template.arg(QString::number(test_number), "lessThan"); + m_flex_test_names.append(new_test_name); + QTest::newRow(m_flex_test_names.last().toLatin1().data()) << first << second << true << false; continue; } @@ -112,8 +115,9 @@ class VersionTest : public QObject { QString first{split_line.first().simplified()}; QString second{split_line.last().simplified()}; - auto new_test_name = test_name_template.arg(QString::number(test_number), "equals").toLatin1().data(); - QTest::newRow(new_test_name) << first << second << false << true; + auto new_test_name = test_name_template.arg(QString::number(test_number), "equals"); + m_flex_test_names.append(new_test_name); + QTest::newRow(m_flex_test_names.last().toLatin1().data()) << first << second << false << true; continue; } @@ -123,8 +127,9 @@ class VersionTest : public QObject { QString first{split_line.first().simplified()}; QString second{split_line.last().simplified()}; - auto new_test_name = test_name_template.arg(QString::number(test_number), "greaterThan").toLatin1().data(); - QTest::newRow(new_test_name) << first << second << false << false; + auto new_test_name = test_name_template.arg(QString::number(test_number), "greaterThan"); + m_flex_test_names.append(new_test_name); + QTest::newRow(m_flex_test_names.last().toLatin1().data()) << first << second << false << false; continue; } @@ -140,10 +145,10 @@ class VersionTest : public QObject { void test_flexVerTestVector() { - QFETCH(QString, first); - QFETCH(QString, second); - QFETCH(bool, lessThan); - QFETCH(bool, equal); + QString first = *static_cast(QTest ::qData("first", ::qMetaTypeId::type>())); + QString second = *static_cast(QTest ::qData("second", ::qMetaTypeId::type>())); + bool lessThan = *static_cast(QTest ::qData("lessThan", ::qMetaTypeId::type>())); + bool equal = *static_cast(QTest ::qData("equal", ::qMetaTypeId::type>())); const auto v1 = Version(first); const auto v2 = Version(second);