1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

Fix for CONC-173: Fixed memory leak in mysql_real_connect

fixed warning in pthread_once
This commit is contained in:
Georg Richter
2016-04-18 09:32:25 +02:00
parent 01f18549dd
commit c70128b50c
4 changed files with 90 additions and 4 deletions

View File

@@ -1802,8 +1802,10 @@ static void mysql_close_memory(MYSQL *mysql)
free(mysql->user);
free(mysql->passwd);
free(mysql->db);
free(mysql->unix_socket);
free(mysql->server_version);
mysql->host_info= mysql->host= mysql->server_version=mysql->user=mysql->passwd=mysql->db=0;
mysql->host_info= mysql->host= mysql->unix_socket=
mysql->server_version=mysql->user=mysql->passwd=mysql->db=0;
}
void my_set_error(MYSQL *mysql,
@@ -3421,12 +3423,22 @@ const char * STDCALL mysql_sqlstate(MYSQL *mysql)
return mysql->net.sqlstate;
}
#ifdef _WIN32
static int mysql_once_init()
#else
static void mysql_once_init()
#endif
{
ma_init(); /* Will init threads */
init_client_errs();
if (mysql_client_plugin_init())
{
#ifdef _WIN32
return 1;
#else
return;
#endif
}
if (!mysql_port)
{
struct servent *serv_ptr;
@@ -3453,7 +3465,9 @@ static int mysql_once_init()
if (!mysql_ps_subsystem_initialized)
mysql_init_ps_subsystem();
mysql_client_init = 1;
#ifdef _WIN32
return 0;
#endif
}
#ifdef _WIN32

View File

@@ -34,7 +34,7 @@ ENDIF()
SET(API_TESTS ${API_TESTS} "async")
#exclude following tests from ctests, since we need to run them maually with different credentials
SET(MANUAL_TESTS "t_aurora")
SET(MANUAL_TESTS "t_aurora" "t_conc173")
# Get finger print from server certificate
IF(WITH_SSL)
IF(OPENSSL_FOUND)

View File

@@ -52,7 +52,7 @@ static int test_conc66(MYSQL *my)
rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my.cnf");
check_mysql_rc(rc, mysql);
sprintf(query, "GRANT ALL ON %s.* TO 'conc66'@'%s' IDENTIFIED BY 'test\";#test'", schema, hostname);
sprintf(query, "GRANT ALL ON %s.* TO 'conc66'@'%s' IDENTIFIED BY 'test\";#test'", schema, hostname ? hostname : "localhost");
rc= mysql_query(my, query);
check_mysql_rc(rc, my);
rc= mysql_query(my, "FLUSH PRIVILEGES");
@@ -64,7 +64,7 @@ static int test_conc66(MYSQL *my)
return FAIL;
}
sprintf(query, "DROP user conc66@%s", hostname);
sprintf(query, "DROP user conc66@%s", hostname ? hostname : "localhost");
rc= mysql_query(my, query);
check_mysql_rc(rc, my);

View File

@@ -0,0 +1,72 @@
/*
Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/C is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
MySQL Connectors. There are special exceptions to the terms and
conditions of the GPLv2 as it is applied to this software, see the
FLOSS License Exception
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
Some basic tests of the client API.
*/
#include "my_test.h"
static int test_conc_173(MYSQL *my)
{
MYSQL mysql;
int arg;
int i=0;
for (;;)
{
mysql_init(&mysql);
mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "client");
mysql_options(&mysql, MYSQL_OPT_COMPRESS, 0);
mysql_options(&mysql, MYSQL_OPT_NAMED_PIPE, 0);
arg = MYSQL_PROTOCOL_SOCKET;
mysql_options(&mysql, MYSQL_OPT_PROTOCOL, &arg);
if(!mysql_real_connect(&mysql, hostname, username, password, schema, 0, 0, 0)) {
fprintf(stderr, "Failed to connect to database after %d iterations: Error: %s\n", i, mysql_error(&mysql));
return 1;
}
mysql_close(&mysql);
}
return OK;
}
struct my_tests_st my_tests[] = {
{"test_conc_173", test_conc_173, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
};
int main(int argc, char **argv)
{
if (argc > 1)
get_options(argc, argv);
get_envvars();
run_tests(my_tests);
return(exit_status());
}