Skip to content

Commit

Permalink
Fix for CONC-277: For backwards compatibiliry we now allow reinitiali…
Browse files Browse the repository at this point in the history
…zation of client library by setting init_once to zero in mysql_server_end() function.
  • Loading branch information
9EOR9 committed Nov 22, 2017
1 parent 683e2f3 commit 15e9ee4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
15 changes: 13 additions & 2 deletions libmariadb/mariadb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,8 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...)
OPT_SET_VALUE_STR(&mysql->options, my_cnf_group, appname);
break;
}
else
OPT_SET_VALUE_STR(&mysql->options, my_cnf_group, (char *)arg1);
break;
case MYSQL_SET_CHARSET_DIR:
OPT_SET_VALUE_STR(&mysql->options, charset_dir, arg1);
Expand Down Expand Up @@ -3592,6 +3594,8 @@ static void mysql_once_init()
}

#ifdef _WIN32
static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;

BOOL CALLBACK win_init_once(
PINIT_ONCE InitOnce,
PVOID Parameter,
Expand All @@ -3600,18 +3604,18 @@ BOOL CALLBACK win_init_once(
return !mysql_once_init();
return TRUE;
}
#else
static pthread_once_t init_once = PTHREAD_ONCE_INIT;
#endif

int STDCALL mysql_server_init(int argc __attribute__((unused)),
char **argv __attribute__((unused)),
char **groups __attribute__((unused)))
{
#ifdef _WIN32
static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
BOOL ret = InitOnceExecuteOnce(&init_once, win_init_once, NULL, NULL);
return ret? 0: 1;
#else
static pthread_once_t init_once = PTHREAD_ONCE_INIT;
return pthread_once(&init_once, mysql_once_init);
#endif
}
Expand All @@ -3632,6 +3636,13 @@ void STDCALL mysql_server_end(void)
#endif
mysql_client_init= 0;
ma_init_done= 0;

/* Fix for CONC-277: Allow reinitialization of client library */
#ifdef WIN32
init_once = INIT_ONCE_STATIC_INIT;
#else
init_once = PTHREAD_ONCE_INIT;
#endif
}

my_bool STDCALL mysql_thread_init(void)
Expand Down
20 changes: 20 additions & 0 deletions unittest/libmariadb/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ if (!(fp= fopen("./mdev13100.cnf", "w")))
diag("Error: %s", mysql_error(mysql));
return FAIL;
}
diag("charset: %s", mysql_character_set_name(mysql));
FAIL_IF(strcmp("latin2", mysql_character_set_name(mysql)), "Expected charset latin2");
mysql_close(mysql);

Expand Down Expand Up @@ -1333,7 +1334,26 @@ static int test_mdev9059_3(MYSQL *my __attribute__((unused)))
return OK;
}

static int test_conc277(MYSQL *my __attribute__((unused)))
{
MYSQL *mysql;


mysql_library_end();
mysql= mysql_init(NULL);
my_test_connect(mysql, hostname, username, password, schema,
port, socketname,
CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS);

diag("error: %s", mysql_error(mysql));
FAIL_IF(mysql_errno(mysql), "No error expected");

mysql_close(mysql);
return OK;
}

struct my_tests_st my_tests[] = {
{"test_conc277", test_conc277, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_mdev9059_1", test_mdev9059_1, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_mdev9059_2", test_mdev9059_2, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_mdev9059_3", test_mdev9059_3, TEST_CONNECTION_NONE, 0, NULL, NULL},
Expand Down

0 comments on commit 15e9ee4

Please sign in to comment.