Skip to content

Commit 9f22350

Browse files
phulakundahlerlend
authored andcommitted
WL#6599 - New Data Dictionary and I_S integration.
This is a post-push patch to fix memory leak identified by the ASAN in the unit test. Issue here is, memory allocated for Dictionary_impl class's instance is not deallocated in the unit test. Modified code to deallocate memory now to fix this issue. Even modified code to create instance of Dictionary_impl class only once at the test start and deallocate at the end.
1 parent 3a37b14 commit 9f22350

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

sql/dd/impl/dictionary_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace dd_schema_unittest {
3030
}
3131

3232
namespace my_testing {
33-
class Server_initializer;
33+
class DD_initializer;
3434
}
3535

3636
namespace dd {
@@ -46,7 +46,7 @@ namespace cache {
4646
class Dictionary_impl : public Dictionary
4747
{
4848
friend class dd_schema_unittest::SchemaTest;
49-
friend class my_testing::Server_initializer;
49+
friend class my_testing::DD_initializer;
5050

5151
/////////////////////////////////////////////////////////////////////////
5252
// Implementation details.

unittest/gunit/test_utils.cc

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "rpl_handler.h" // delegates_init()
2222
#include "mysqld_thd_manager.h" // Global_THD_manager
2323
#include "opt_costconstantcache.h" // optimizer cost constant cache
24+
#include "my_dbug.h" // DBUG_ASSERT
2425
#include "mysqld.h" // set_remaining_args
2526
#include "log.h" // query_logger
2627

@@ -67,6 +68,7 @@ void setup_server_for_unit_tests()
6768
// Initialize Query_logger last, to avoid spurious warnings to stderr.
6869
query_logger.init();
6970
init_optimizer_cost_module(false);
71+
DD_initializer::SetUp();
7072
}
7173

7274
void teardown_server_for_unit_tests()
@@ -77,6 +79,7 @@ void teardown_server_for_unit_tests()
7779
gtid_server_cleanup();
7880
query_logger.cleanup();
7981
delete_optimizer_cost_module();
82+
DD_initializer::TearDown();
8083
}
8184

8285
void Server_initializer::set_expected_error(uint val)
@@ -96,15 +99,6 @@ void Server_initializer::SetUp()
9699
m_thd->store_globals();
97100
lex_start(m_thd);
98101

99-
/*
100-
With WL#6599, SELECT_LEX::add_table_to_list() will invoke
101-
dd::Dictionary::is_system_view_name() method. E.g., the unit
102-
test InsertDelayed would invoke above API. This requires us
103-
to have a instance of dictionary_impl. We do not really need
104-
to initialize dd::System_views for this test. Also, there can
105-
be future test cases that need the same.
106-
*/
107-
dd::Dictionary_impl::s_instance= new dd::Dictionary_impl();
108102
}
109103

110104
void Server_initializer::TearDown()
@@ -149,5 +143,24 @@ bool Mock_error_handler::handle_condition(THD *thd,
149143
return true;
150144
}
151145

146+
void DD_initializer::SetUp()
147+
{
148+
/*
149+
With WL#6599, SELECT_LEX::add_table_to_list() will invoke
150+
dd::Dictionary::is_system_view_name() method. E.g., the unit
151+
test InsertDelayed would invoke above API. This requires us
152+
to have a instance of dictionary_impl. We do not really need
153+
to initialize dd::System_views for this test. Also, there can
154+
be future test cases that need the same.
155+
*/
156+
dd::Dictionary_impl::s_instance= new (std::nothrow)dd::Dictionary_impl();
157+
DBUG_ASSERT(dd::Dictionary_impl::s_instance != nullptr);
158+
}
159+
160+
void DD_initializer::TearDown()
161+
{
162+
DBUG_ASSERT(dd::Dictionary_impl::s_instance != nullptr);
163+
delete dd::Dictionary_impl::s_instance;
164+
}
152165

153166
} // namespace my_testing

unittest/gunit/test_utils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ void expect_null(T *t)
111111
EXPECT_EQ(t_null, t);
112112
}
113113

114+
/*
115+
A class which wraps the necessary setup/teardown logic for
116+
Data Dictionary.
117+
*/
118+
class DD_initializer
119+
{
120+
public:
121+
static void SetUp();
122+
static void TearDown();
123+
};
114124

115125
} // namespace my_testing
116126

0 commit comments

Comments
 (0)