3799 Georgi Kodinov 2012-03-12
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.
added:
mysql-test/r/bug12969156.result
mysql-test/t/bug12969156-master.opt
mysql-test/t/bug12969156.test
modified:
plugin/daemon_example/daemon_example.cc
3798 Guilhem Bichot 2012-03-19
fix for Bug#13860138 BUILD BREAK WHEN COMPILING WITHOUT OPT_TRACE
modified:
sql/opt_range.cc
sql/opt_trace_context.h
=== added file 'mysql-test/r/bug12969156.result'
--- a/mysql-test/r/bug12969156.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/bug12969156.result 2012-03-12 15:37:47 +0000
@@ -0,0 +1,24 @@
+#
+# Bug #12969156 : SEGMENTATION FAULT ON UNINSTALLING
+# DAEMON_EXAMPLE PLUGIN
+#
+INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
+UNINSTALL PLUGIN daemon_example;
+INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
+UNINSTALL PLUGIN daemon_example;
+INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
+UNINSTALL PLUGIN daemon_example;
+INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
+UNINSTALL PLUGIN daemon_example;
+INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
+UNINSTALL PLUGIN daemon_example;
+INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
+UNINSTALL PLUGIN daemon_example;
+INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
+UNINSTALL PLUGIN daemon_example;
+INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
+UNINSTALL PLUGIN daemon_example;
+INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
+UNINSTALL PLUGIN daemon_example;
+INSTALL PLUGIN daemon_example SONAME 'DAEMONEXAMPLE';
+UNINSTALL PLUGIN daemon_example;
=== added file 'mysql-test/t/bug12969156-master.opt'
--- a/mysql-test/t/bug12969156-master.opt 1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/bug12969156-master.opt 2012-03-12 15:37:47 +0000
@@ -0,0 +1 @@
+--plugin-dir=$DAEMONEXAMPLE_DIR
=== added file 'mysql-test/t/bug12969156.test'
--- a/mysql-test/t/bug12969156.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/bug12969156.test 2012-03-12 15:37:47 +0000
@@ -0,0 +1,15 @@
+--source include/not_embedded.inc
+
+--echo #
+--echo # Bug #12969156 : SEGMENTATION FAULT ON UNINSTALLING
+--echo # DAEMON_EXAMPLE PLUGIN
+--echo #
+
+let $counter= 0;
+while ($counter < 10)
+{
+--replace_result $DAEMONEXAMPLE DAEMONEXAMPLE
+ eval INSTALL PLUGIN daemon_example SONAME '$DAEMONEXAMPLE';
+ UNINSTALL PLUGIN daemon_example;
+ inc $counter;
+}
=== modified file 'plugin/daemon_example/daemon_example.cc'
--- a/plugin/daemon_example/daemon_example.cc 2012-03-06 14:29:42 +0000
+++ b/plugin/daemon_example/daemon_example.cc 2012-03-12 15:37:47 +0000
@@ -46,7 +46,6 @@ pthread_handler_t mysql_heartbeat(void *
DBUG_ENTER("mysql_heartbeat");
struct mysql_heartbeat_context *con= (struct mysql_heartbeat_context *)p;
char buffer[HEART_STRING_BUFFER];
- unsigned int x= 0;
time_t result;
struct tm tm_tmp;
@@ -65,7 +64,6 @@ pthread_handler_t mysql_heartbeat(void *
tm_tmp.tm_min,
tm_tmp.tm_sec);
my_write(con->heartbeat_file, (uchar*) buffer, strlen(buffer), MYF(0));
- x++;
}
DBUG_RETURN(0);
@@ -160,6 +158,7 @@ static int daemon_example_plugin_deinit(
(struct mysql_heartbeat_context *)plugin->data;
time_t result= time(NULL);
struct tm tm_tmp;
+ void *dummy_retval;
pthread_cancel(con->heartbeat_thread);
@@ -173,6 +172,13 @@ static int daemon_example_plugin_deinit(
tm_tmp.tm_min,
tm_tmp.tm_sec);
my_write(con->heartbeat_file, (uchar*) buffer, strlen(buffer), MYF(0));
+
+ /*
+ Need to wait for the hearbeat thread to terminate before closing
+ the file it writes to and freeing the memory it uses
+ */
+ pthread_join(con->heartbeat_thread, &dummy_retval);
+
my_close(con->heartbeat_file, MYF(0));
my_free(con);
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-trunk branch (Georgi.Kodinov:3798 to 3799) Bug#12969156 | Georgi Kodinov | 19 Mar |