Skip to content

Commit ceab37d

Browse files
committed
Bug#22833138: MYSQL CLIENT MEMORY LEAK AFTER THE SERVER HAS SHUT DOWN
Workaround: Since the memory leaks reported in Bug#22833138 are coming from the (external to the MySQL server) KEYRING_OKV SDK, they will not be fixed. Adding all of the leak locations to Valgrind ignore list. But the plugin system automatically unloads the shared libraries so the valgrind cannot correctly report the leaks. Disabling the shared library unload if ran through valgrind. The side effect is the memory used by the shared object is not released. This is not a big problem anyway, and valgrind itself is very memory intensive. But further reloading of the same shared object succeeds, so all the tests run fine.
1 parent fe71e91 commit ceab37d

File tree

2 files changed

+172
-12
lines changed

2 files changed

+172
-12
lines changed

mysql-test/valgrind.supp

Lines changed: 142 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@
10031003
fun:_Z*8clean_upb*
10041004
}
10051005

1006-
#Suppress warnings from glibc implementation of 'malloc_info'
1006+
#Suppress warnings from glibc implementation of 'malloc_info'
10071007
{
10081008
Malloc_info uninitialised value of size 8
10091009
Memcheck:Value8
@@ -1479,7 +1479,7 @@
14791479
...
14801480
}
14811481

1482-
{
1482+
{
14831483
TPL leak 11
14841484
Memcheck:Leak
14851485
match-leak-kinds: reachable
@@ -1493,7 +1493,7 @@
14931493
fun:by_file_ctrl
14941494
fun:X509_STORE_load_locations
14951495
obj:*
1496-
obj:*
1496+
obj:*
14971497
obj:*
14981498
obj:*
14991499
obj:*
@@ -1707,3 +1707,142 @@
17071707
fun:ppoll
17081708
fun:vio_io_wait
17091709
}
1710+
1711+
# Workarounds for
1712+
#
1713+
# Bug#22833138 KEYRING_OKV : MEMORY LEAKS FROM OKV CLIENT LIB
1714+
{
1715+
Keyring_OKV_workaround_addtoTagObj
1716+
Memcheck:Leak
1717+
fun:malloc
1718+
fun:okimem_nat_malloc
1719+
fun:OKIMemAlloc
1720+
fun:addtoTagObj
1721+
}
1722+
{
1723+
Keyring_OKV_workaround_OKIGetKey
1724+
Memcheck:Leak
1725+
fun:malloc
1726+
fun:okimem_nat_malloc
1727+
fun:OKIMemAlloc
1728+
fun:OKIAPIResultAlloc
1729+
fun:OKIGetKey
1730+
}
1731+
{
1732+
Keyring_OKV_workaround_OKICreateKey
1733+
Memcheck:Leak
1734+
fun:malloc
1735+
fun:okimem_nat_malloc
1736+
fun:OKIMemAlloc
1737+
fun:OKIAPIResultAlloc
1738+
fun:OKICreateKey
1739+
}
1740+
{
1741+
Keyring_OKV_workaround_OKIGetAttributes
1742+
Memcheck:Leak
1743+
fun:malloc
1744+
fun:okimem_nat_malloc
1745+
fun:OKIMemAlloc
1746+
fun:OKIAPIResultAlloc
1747+
fun:OKIGetAttributes
1748+
}
1749+
{
1750+
Keyring_OKV_workaround_OKIGetAttributes2
1751+
Memcheck:Leak
1752+
fun:malloc
1753+
fun:okimem_nat_malloc
1754+
fun:OKIMemAlloc
1755+
fun:OKIPostGetUIDTTLV
1756+
fun:OKIAPIPostProcessing
1757+
fun:OKIGetAttributes
1758+
}
1759+
{
1760+
Keyring_OKV_workaround_OKIAddAttribute
1761+
Memcheck:Leak
1762+
fun:malloc
1763+
fun:okimem_nat_malloc
1764+
fun:OKIMemAlloc
1765+
fun:OKIAPIResultAlloc
1766+
fun:OKIAddAttribute
1767+
}
1768+
{
1769+
Keyring_OKV_workaround_OKIAddAttribute2
1770+
Memcheck:Leak
1771+
match-leak-kinds: definite
1772+
fun:malloc
1773+
fun:okimem_nat_malloc
1774+
fun:OKIMemAlloc
1775+
fun:OKIOpsCreate
1776+
fun:OKIAddAttribute
1777+
}
1778+
{
1779+
Keyring_OKV_workaround_OKILocate
1780+
Memcheck:Leak
1781+
match-leak-kinds: definite
1782+
fun:malloc
1783+
fun:okimem_nat_malloc
1784+
fun:OKIMemAlloc
1785+
fun:OKIAPIResultAlloc
1786+
fun:OKILocate
1787+
}
1788+
{
1789+
Keyring_OKV_workaround_OKIActivate
1790+
Memcheck:Leak
1791+
fun:malloc
1792+
fun:okimem_nat_malloc
1793+
fun:OKIMemAlloc
1794+
fun:OKIAPIResultAlloc
1795+
fun:OKIActivate
1796+
}
1797+
{
1798+
Keyring_OKV_workaround_OKIRegKey
1799+
Memcheck:Leak
1800+
match-leak-kinds: definite
1801+
fun:malloc
1802+
fun:okimem_nat_malloc
1803+
fun:OKIMemAlloc
1804+
fun:OKIAPIResultAlloc
1805+
fun:OKIRegKey
1806+
}
1807+
{
1808+
Keyring_OKV_workaround_OKIRevoke
1809+
Memcheck:Leak
1810+
fun:malloc
1811+
fun:okimem_nat_malloc
1812+
fun:OKIMemAlloc
1813+
fun:OKIAPIResultAlloc
1814+
fun:OKIRevoke
1815+
}
1816+
{
1817+
Keyring_OKV_workaround_OKIEnvCreate
1818+
Memcheck:Leak
1819+
match-leak-kinds: definite
1820+
fun:malloc
1821+
fun:okimem_nat_malloc
1822+
fun:OKIMemAlloc
1823+
fun:OKIEnvCreate
1824+
}
1825+
{
1826+
Keyring_OKV_workaround_OKITTLVMoveChildWithTag
1827+
Memcheck:Leak
1828+
fun:malloc
1829+
fun:okimem_nat_malloc
1830+
fun:OKIMemAlloc
1831+
fun:OKITTLVMoveChildWithTag
1832+
}
1833+
{
1834+
Keyring_OKV_workaround_OKIParseUnpackTTLVFromBuffer
1835+
Memcheck:Leak
1836+
fun:malloc
1837+
fun:okimem_nat_malloc
1838+
fun:OKIMemAlloc
1839+
fun:OKIParseUnpackTTLVFromBuffer
1840+
}
1841+
{
1842+
Keyring_OKV_workaround_OKITTLVAddChildObject
1843+
Memcheck:Leak
1844+
fun:malloc
1845+
fun:okimem_nat_malloc
1846+
fun:OKIMemAlloc
1847+
fun:OKITTLVAddChildObject
1848+
}

sql/sql_plugin.cc

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,17 @@ static st_plugin_dl *plugin_dl_insert_or_reuse(st_plugin_dl *plugin_dl)
556556

557557
static inline void free_plugin_mem(st_plugin_dl *p)
558558
{
559+
#ifdef HAVE_VALGRIND
560+
/*
561+
The valgrind leak report is done at the end of the program execution.
562+
But since the plugins are unloaded from the memory,
563+
it is impossible for valgrind to correctly report the leak locations.
564+
So leave the shared objects (.DLL/.so) open for the symbols definition.
565+
*/
566+
#else /* not HAVE_VALGRIND */
559567
if (p->handle)
560568
dlclose(p->handle);
569+
#endif
561570
my_free(p->dl.str);
562571
if (p->version != MYSQL_PLUGIN_INTERFACE_VERSION)
563572
my_free(p->plugins);
@@ -1111,6 +1120,12 @@ static void plugin_deinitialize(st_plugin_int *plugin, bool ref_check)
11111120
plugin->name.str, plugin->ref_count);
11121121
}
11131122

1123+
/*
1124+
Unload a plugin.
1125+
Note: During valgrind testing, the plugin's shared object (.dll/.so)
1126+
is not unloaded in order to keep the call stack
1127+
of the leaked objects.
1128+
*/
11141129
static void plugin_del(st_plugin_int *plugin)
11151130
{
11161131
DBUG_ENTER("plugin_del(plugin)");
@@ -1978,6 +1993,12 @@ void memcached_shutdown(void)
19781993
}
19791994
}
19801995

1996+
/*
1997+
Deinitialize and unload all the loaded plugins.
1998+
Note: During valgrind testing, the shared objects (.dll/.so)
1999+
are not unloaded in order to keep the call stack
2000+
of the leaked objects.
2001+
*/
19812002
void plugin_shutdown(void)
19822003
{
19832004
size_t i;
@@ -2844,7 +2865,7 @@ static st_bookmark *register_var(const char *plugin, const char *name,
28442865
string.
28452866
*/
28462867
memset(global_system_variables.dynamic_variables_ptr +
2847-
global_variables_dynamic_size, 0,
2868+
global_variables_dynamic_size, 0,
28482869
new_size - global_variables_dynamic_size);
28492870
memset(max_system_variables.dynamic_variables_ptr +
28502871
global_variables_dynamic_size, 0,
@@ -3028,11 +3049,11 @@ void plugin_thdvar_init(THD *thd, bool enable_plugins)
30283049
plugin_ref old_table_plugin= thd->variables.table_plugin;
30293050
plugin_ref old_temp_table_plugin= thd->variables.temp_table_plugin;
30303051
DBUG_ENTER("plugin_thdvar_init");
3031-
3052+
30323053
thd->variables.table_plugin= NULL;
30333054
thd->variables.temp_table_plugin= NULL;
30343055
cleanup_variables(thd, &thd->variables);
3035-
3056+
30363057
mysql_mutex_lock(&LOCK_global_system_variables);
30373058
thd->variables= global_system_variables;
30383059
thd->variables.table_plugin= NULL;
@@ -3088,7 +3109,7 @@ static void cleanup_variables(THD *thd, struct System_variables *vars)
30883109
{
30893110
/* Block the Performance Schema from accessing THD::variables. */
30903111
mysql_mutex_lock(&thd->LOCK_thd_data);
3091-
3112+
30923113
plugin_var_memalloc_free(&thd->variables);
30933114
thd->session_sysvar_res_mgr.deinit();
30943115
}
@@ -3457,7 +3478,7 @@ static int construct_options(MEM_ROOT *mem_root, st_plugin_int *tmp,
34573478
if (opt->flags & PLUGIN_VAR_NOCMDOPT)
34583479
continue;
34593480

3460-
optname= (char*) memdup_root(mem_root, v->key + 1,
3481+
optname= (char*) memdup_root(mem_root, v->key + 1,
34613482
(optnamelen= v->name_len) + 1);
34623483
}
34633484

@@ -3722,7 +3743,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, st_plugin_int *tmp,
37223743
}
37233744
}
37243745
DBUG_RETURN(0);
3725-
3746+
37263747
err:
37273748
if (opts)
37283749
my_cleanup_options(opts);
@@ -3757,7 +3778,7 @@ void add_plugin_options(std::vector<my_option> *options, MEM_ROOT *mem_root)
37573778
}
37583779
}
37593780

3760-
/**
3781+
/**
37613782
Searches for a correctly loaded plugin of a particular type by name
37623783
37633784
@param plugin the name of the plugin we're looking for
@@ -3774,7 +3795,7 @@ st_plugin_int *plugin_find_by_type(const LEX_CSTRING &plugin, int type)
37743795
}
37753796

37763797

3777-
/**
3798+
/**
37783799
Locks the plugin strucutres so calls to plugin_find_inner can be issued.
37793800
37803801
Must be followed by unlock_plugin_data.
@@ -3786,7 +3807,7 @@ int lock_plugin_data()
37863807
}
37873808

37883809

3789-
/**
3810+
/**
37903811
Unlocks the plugin strucutres as locked by lock_plugin_data()
37913812
*/
37923813
int unlock_plugin_data()

0 commit comments

Comments
 (0)