Skip to content

Commit 57acdd1

Browse files
committed
Bug #12969156: SEGMENTATION FAULT ON UNINSTALLING
DAEMON_EXAMPLE PLUGIN The deinit() function of the daemon example plugin was calling pthread_cancel, but not waiting for the worker thread to actually complete before deallocating the data buffer and closing the file that it writes to. Fixed by adding a pthread_join to wait for the thread to complete before doing the cleanup work that may affect it. Test case added. Removed a stray 'x' variable from the example code.
1 parent 4e36c9e commit 57acdd1

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

mysql-test/r/bug12969156.result

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Bug #12969156 : SEGMENTATION FAULT ON UNINSTALLING
3+
# DAEMON_EXAMPLE PLUGIN
4+
#
5+
INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
6+
UNINSTALL PLUGIN daemon_example;
7+
INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
8+
UNINSTALL PLUGIN daemon_example;
9+
INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
10+
UNINSTALL PLUGIN daemon_example;
11+
INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
12+
UNINSTALL PLUGIN daemon_example;
13+
INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
14+
UNINSTALL PLUGIN daemon_example;
15+
INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
16+
UNINSTALL PLUGIN daemon_example;
17+
INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
18+
UNINSTALL PLUGIN daemon_example;
19+
INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
20+
UNINSTALL PLUGIN daemon_example;
21+
INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
22+
UNINSTALL PLUGIN daemon_example;
23+
INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
24+
UNINSTALL PLUGIN daemon_example;

mysql-test/t/bug12969156-master.opt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--plugin-dir=$DAEMONEXAMPLE_DIR

mysql-test/t/bug12969156.test

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--source include/not_embedded.inc
2+
3+
--echo #
4+
--echo # Bug #12969156 : SEGMENTATION FAULT ON UNINSTALLING
5+
--echo # DAEMON_EXAMPLE PLUGIN
6+
--echo #
7+
8+
let $counter= 0;
9+
while ($counter < 10)
10+
{
11+
--replace_result $DAEMONEXAMPLE DAEMONEXAMPLE
12+
eval INSTALL PLUGIN daemon_example SONAME '$DAEMONEXAMPLE';
13+
UNINSTALL PLUGIN daemon_example;
14+
inc $counter;
15+
}

plugin/daemon_example/daemon_example.cc

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pthread_handler_t mysql_heartbeat(void *p)
4646
DBUG_ENTER("mysql_heartbeat");
4747
struct mysql_heartbeat_context *con= (struct mysql_heartbeat_context *)p;
4848
char buffer[HEART_STRING_BUFFER];
49-
unsigned int x= 0;
5049
time_t result;
5150
struct tm tm_tmp;
5251

@@ -65,7 +64,6 @@ pthread_handler_t mysql_heartbeat(void *p)
6564
tm_tmp.tm_min,
6665
tm_tmp.tm_sec);
6766
my_write(con->heartbeat_file, (uchar*) buffer, strlen(buffer), MYF(0));
68-
x++;
6967
}
7068

7169
DBUG_RETURN(0);
@@ -160,6 +158,7 @@ static int daemon_example_plugin_deinit(void *p)
160158
(struct mysql_heartbeat_context *)plugin->data;
161159
time_t result= time(NULL);
162160
struct tm tm_tmp;
161+
void *dummy_retval;
163162

164163
pthread_cancel(con->heartbeat_thread);
165164

@@ -173,6 +172,13 @@ static int daemon_example_plugin_deinit(void *p)
173172
tm_tmp.tm_min,
174173
tm_tmp.tm_sec);
175174
my_write(con->heartbeat_file, (uchar*) buffer, strlen(buffer), MYF(0));
175+
176+
/*
177+
Need to wait for the hearbeat thread to terminate before closing
178+
the file it writes to and freeing the memory it uses
179+
*/
180+
pthread_join(con->heartbeat_thread, &dummy_retval);
181+
176182
my_close(con->heartbeat_file, MYF(0));
177183

178184
my_free(con);

0 commit comments

Comments
 (0)