diff --git a/include/mysql_com.h b/include/mysql_com.h index 3eba8a84..d8b8c5bd 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -151,6 +151,7 @@ enum enum_server_command #define CLIENT_PLUGIN_AUTH (1UL << 19) #define CLIENT_PROGRESS (1UL << 29) /* client supports progress indicator */ #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30) +#define CLIENT_REMEMBER_OPTIONS (1UL << 31) #define CLIENT_SUPPORTED_FLAGS (CLIENT_LONG_PASSWORD | \ CLIENT_FOUND_ROWS |\ @@ -171,7 +172,8 @@ enum enum_server_command CLIENT_MULTI_STATEMENTS |\ CLIENT_MULTI_RESULTS |\ CLIENT_PROGRESS |\ - CLIENT_SSL_VERIFY_SERVER_CERT) + CLIENT_SSL_VERIFY_SERVER_CERT |\ + CLIENT_REMEMBER_OPTIONS) #define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD |\ CLIENT_LONG_FLAG |\ diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 7bdaee72..9e90850c 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -65,6 +65,7 @@ #endif static my_bool mysql_client_init=0; +static void mysql_close_options(MYSQL *mysql); extern my_bool my_init_done; extern my_bool mysql_ps_subsystem_initialized; extern my_bool mysql_handle_local_infile(MYSQL *mysql, const char *filename); @@ -1858,6 +1859,8 @@ error: end_server(mysql); /* only free the allocated memory, user needs to call mysql_close */ mysql_close_memory(mysql); + if (!(((ulong) client_flag) & CLIENT_REMEMBER_OPTIONS)) + mysql_close_options(mysql); } DBUG_RETURN(0); } diff --git a/unittest/libmariadb/connection.c b/unittest/libmariadb/connection.c index dacb91e9..7a27bca5 100644 --- a/unittest/libmariadb/connection.c +++ b/unittest/libmariadb/connection.c @@ -560,6 +560,27 @@ int test_conc21(MYSQL *mysql) return OK; } +int test_conc26(MYSQL *my) +{ + MYSQL *mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8"); + + FAIL_IF(mysql_real_connect(mysql, hostname, "notexistinguser", "password", schema, port, NULL, CLIENT_REMEMBER_OPTIONS), + "Error expected"); + + FAIL_IF(!mysql->options.charset_name || strcmp(mysql->options.charset_name, "utf8") != 0, + "expected charsetname=utf8"); + mysql_close(mysql); + + mysql= mysql_init(NULL); + FAIL_IF(mysql_real_connect(mysql, hostname, "notexistinguser", "password", schema, port, NULL, 0), + "Error expected"); + FAIL_IF(mysql->options.charset_name, "Error: options not freed"); + mysql_close(mysql); + + return OK; +} + struct my_tests_st my_tests[] = { {"test_bug20023", test_bug20023, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_bug31669", test_bug31669, TEST_CONNECTION_NEW, 0, NULL, NULL}, @@ -569,6 +590,7 @@ struct my_tests_st my_tests[] = { {"test_compress", test_compress, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_reconnect", test_reconnect, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc21", test_conc21, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc26", test_conc26, TEST_CONNECTION_NONE, 0, NULL, NULL}, {NULL, NULL, 0, 0, NULL, NULL} };