add suppressions for leak sanitizer

This commit is contained in:
Alexander Tokmakov 2020-09-03 22:50:26 +03:00
parent 9d98effa5e
commit df09bf3cb6
7 changed files with 124 additions and 2 deletions

View File

@ -35,6 +35,7 @@ echo "UBSAN_OPTIONS='print_stacktrace=1'" >> /etc/environment
echo "ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-10/bin/llvm-symbolizer" >> /etc/environment
echo "UBSAN_SYMBOLIZER_PATH=/usr/lib/llvm-10/bin/llvm-symbolizer" >> /etc/environment
echo "LLVM_SYMBOLIZER_PATH=/usr/lib/llvm-10/bin/llvm-symbolizer" >> /etc/environment
echo "LSAN_OPTIONS='suppressions=/usr/share/clickhouse-test/config/lsan_suppressions.txt'" >> /etc/environment
service zookeeper start
sleep 5

View File

@ -53,6 +53,7 @@ echo "UBSAN_OPTIONS='print_stacktrace=1'" >> /etc/environment
echo "ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-10/bin/llvm-symbolizer" >> /etc/environment
echo "UBSAN_SYMBOLIZER_PATH=/usr/lib/llvm-10/bin/llvm-symbolizer" >> /etc/environment
echo "LLVM_SYMBOLIZER_PATH=/usr/lib/llvm-10/bin/llvm-symbolizer" >> /etc/environment
echo "LSAN_OPTIONS='suppressions=/usr/share/clickhouse-test/config/lsan_suppressions.txt'" >> /etc/environment
service zookeeper start
sleep 5

View File

@ -6,3 +6,7 @@ list(REMOVE_ITEM clickhouse_table_functions_headers ITableFunction.h TableFuncti
add_library(clickhouse_table_functions ${clickhouse_table_functions_sources})
target_link_libraries(clickhouse_table_functions PRIVATE clickhouse_parsers clickhouse_storages_system dbms)
if(ENABLE_TESTS)
add_subdirectory(tests)
endif()

View File

@ -20,8 +20,7 @@ StoragePtr ITableFunction::execute(const ASTPtr & ast_function, const Context &
ProfileEvents::increment(ProfileEvents::TableFunctionExecute);
context.checkAccess(AccessType::CREATE_TEMPORARY_TABLE | StorageFactory::instance().getSourceAccessType(getStorageTypeName()));
bool no_conversion_required = hasStaticStructure() && cached_columns == getActualTableStructure(context);
if (cached_columns.empty() || no_conversion_required)
if (cached_columns.empty() || (hasStaticStructure() && cached_columns == getActualTableStructure(context)))
return executeImpl(ast_function, context, table_name, std::move(cached_columns));
auto get_storage = [=, tf = shared_from_this()]() -> StoragePtr

View File

@ -0,0 +1,2 @@
add_executable (test-strange-memory-leak test_strange_memory_leak.cpp ${SRCS})
#target_link_libraries (test-strange-memory-leak PRIVATE dbms)

View File

@ -0,0 +1,113 @@
/// Demonstrates mysterious memory leak when built using clang version 10.0.0-4ubuntu1~18.04.2
/// Ne leaks are found by valgrind when built using gcc version 9.2.1 20191102
//#include <DataTypes/IDataType.h>
//#include <Storages/ColumnsDescription.h>
//class ITableFunction : public std::enable_shared_from_this<ITableFunction>
//{
//public:
// virtual DB::ColumnsDescription getActualTableStructure() const = 0;
// virtual ~ITableFunction() {}
//
//};
//
//class TableFunction : public ITableFunction
//{
// DB::ColumnsDescription getActualTableStructure() const override
// {
// return DB::ColumnsDescription({{"number", DB::DataTypePtr{}}});
// }
//};
//
//template <bool multithreaded>
//class TableFunctionTemplate : public ITableFunction
//{
// DB::ColumnsDescription getActualTableStructure() const override
// {
// return DB::ColumnsDescription({{"number", DB::DataTypePtr{}}});
// }
//};
/// Simplified version of the commented code above (without dependencies on ClickHouse code):
#include <memory>
#include <string>
#include <list>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/member.hpp>
using LolPtr = std::shared_ptr<std::string>;
struct Elem
{
Elem(std::string n, LolPtr t) : name(std::move(n)), type(std::move(t)) {}
std::string name;
LolPtr type;
};
using Container = boost::multi_index_container<
Elem,
boost::multi_index::indexed_by<
boost::multi_index::sequenced<>,
boost::multi_index::ordered_unique<boost::multi_index::member<Elem, std::string, &Elem::name>>>>;
struct List : public std::list<Elem>
{
List(std::initializer_list<Elem> init) : std::list<Elem>(init) {}
};
struct Kek
{
Container container;
Kek(List list)
{
for (auto & elem : list)
add(Elem(std::move(elem.name), std::move(elem.type)));
}
void add(Elem column)
{
auto insert_it = container.cbegin();
container.get<0>().insert(insert_it, std::move(column));
}
};
class ITableFunction : public std::enable_shared_from_this<ITableFunction>
{
public:
virtual Kek getActualTableStructure() const = 0;
virtual ~ITableFunction() {}
};
class TableFunction : public ITableFunction
{
Kek getActualTableStructure() const override
{
return Kek({{"number", LolPtr{}}});
}
};
template <bool multithreaded>
class TableFunctionTemplate : public ITableFunction
{
Kek getActualTableStructure() const override
{
return Kek({{"number", LolPtr{}}});
}
};
int main()
{
/// Works fine
const ITableFunction & tf1 = TableFunction{};
tf1.getActualTableStructure();
/// ERROR: LeakSanitizer: detected memory leaks
/// and the same error with valgrind
const ITableFunction & tf2 = TableFunctionTemplate<false>{};
tf2.getActualTableStructure();
}

View File

@ -0,0 +1,2 @@
# See src/TableFunctions/tests/test-strange-memory-leak.cpp
leak:getActualTableStructure