File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,21 @@ typedef struct sql_type_info_s
5757 int is_num ;
5858} sql_type_info_t ;
5959
60+ /*
61+ Ensure we only call mysql_library_init once, since that is not threadsafe.
62+ Not doing this before had lead to crashes in Apache MPM workers.
63+ */
64+ pthread_once_t once_mysql_initialized = PTHREAD_ONCE_INIT ;
65+
66+ static void init_mysql_library (void )
67+ {
68+ mysql_library_init (0 , NULL , NULL );
69+ }
70+
71+ static void ensure_mysql_initialized ()
72+ {
73+ pthread_once (& once_mysql_initialized , init_mysql_library );
74+ }
6075
6176/*
6277
@@ -1206,7 +1221,7 @@ MYSQL *mysql_dr_connect(
12061221#else
12071222 client_flag = CLIENT_FOUND_ROWS ;
12081223#endif
1209- mysql_library_init ( 0 , NULL , NULL );
1224+ ensure_mysql_initialized ( );
12101225 mysql_init (sock );
12111226
12121227 if (imp_dbh )
Original file line number Diff line number Diff line change 2222#include <mysql.h> /* Comes with MySQL-devel */
2323#include <mysqld_error.h> /* Comes MySQL */
2424#include <errmsg.h> /* Comes with MySQL-devel */
25-
25+ #include <pthread.h>
2626
2727#define true 1
2828#define false 0
You can’t perform that action at this time.
0 commit comments