Skip to content

Commit 24fe201

Browse files
committed
Fixed memory leaks reported by ASan
WL#8338 Memory allocated for Unit-test was not being released. Global data kept by ProtoBuf was not being released if plugin was uninstalled before server shutdown.
1 parent cc49207 commit 24fe201

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

rapid/plugin/x/src/xpl_plugin.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ char *xpl_func_ptr(Xpl_status_variable_get callback)
5252
return ptr_cast.ptr;
5353
}
5454

55+
56+
static void exit_hook()
57+
{
58+
google::protobuf::ShutdownProtobufLibrary();
59+
}
60+
61+
5562
/*
5663
Start the plugin: start webservers
5764
@@ -65,6 +72,13 @@ char *xpl_func_ptr(Xpl_status_variable_get callback)
6572
*/
6673
int xpl_plugin_init(MYSQL_PLUGIN p)
6774
{
75+
static bool atexit_installed = false;
76+
if (!atexit_installed)
77+
{
78+
atexit_installed = true;
79+
atexit(exit_hook);
80+
}
81+
6882
xpl::Plugin_system_variables::clean_callbacks();
6983

7084
xpl_init_performance_schema();

rapid/plugin/x/src/xpl_replication_observer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ using namespace xpl;
2626

2727
int xpl_before_server_shutdown(Server_state_param *param)
2828
{
29-
google::protobuf::ShutdownProtobufLibrary();
29+
// google::protobuf::ShutdownProtobufLibrary();
3030

3131
return 0;
3232
}

rapid/unittest/gunit/xplugin/obuffer_t.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <string>
2222
#include <iostream>
2323

24+
#include <boost/shared_ptr.hpp>
2425
#include <gtest/gtest.h>
2526

2627
#include "ngs/protocol/output_buffer.h"
@@ -32,12 +33,14 @@ namespace im
3233
const ngs::Pool_config default_pool_config = { 0, 0, BUFFER_PAGE_SIZE };
3334

3435
namespace tests {
36+
std::vector<boost::shared_ptr<Page> > page_del;
3537

3638
static void add_pages(Output_buffer &ob, const size_t no_of_pages, const size_t page_size)
3739
{
3840
for (size_t i = 0; i < no_of_pages; i++)
3941
{
40-
ob.push_back(new Page(page_size));
42+
page_del.push_back(boost::shared_ptr<Page>(new Page(page_size)));
43+
ob.push_back(page_del.back().get());
4144
}
4245
}
4346

rapid/unittest/gunit/xplugin/row_builder_t.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <gtest/gtest.h>
1818
#include <boost/scoped_ptr.hpp>
19+
#include <boost/shared_ptr.hpp>
1920
#include <mysql/service_my_snprintf.h>
2021
#include <limits>
2122
#include <string>
@@ -43,11 +44,14 @@ typedef ngs::Page_pool Page_pool;
4344

4445
const ngs::Pool_config default_pool_config = { 0, 0, BUFFER_PAGE_SIZE };
4546

47+
static std::vector<boost::shared_ptr<ngs::Page> > page_del;
48+
4649
static void add_pages(Output_buffer *ob, const size_t no_of_pages, const size_t page_size)
4750
{
4851
for (size_t i = 0; i < no_of_pages; i++)
4952
{
50-
ngs::Resource<ngs::Page> page(new ngs::Page(page_size));
53+
page_del.push_back(boost::shared_ptr<ngs::Page>(new ngs::Page(page_size)));
54+
ngs::Resource<ngs::Page> page(page_del.back().get());
5155
ob->push_back(page);
5256
}
5357
}

0 commit comments

Comments
 (0)