From 836db563721ddd6bcfc35b5dcc39f1ea2c970f00 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 23 Jan 2025 19:54:44 +0100 Subject: [PATCH 1/3] memory leaks after CONC-589, e09e24e8 we cannot just set `mysql->net.pvio= NULL` we need to free(net->pvio) first. And not protect `free(net->buff)` with `if (mysql->net.pvio)`. --- libmariadb/mariadb_lib.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libmariadb/mariadb_lib.c b/libmariadb/mariadb_lib.c index 9cebe6df..0056368c 100644 --- a/libmariadb/mariadb_lib.c +++ b/libmariadb/mariadb_lib.c @@ -387,6 +387,7 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, (socket) is still available */ if (command != COM_QUIT && mysql->options.reconnect && ma_pvio_is_alive(mysql->net.pvio)) { + ma_pvio_close(mysql->net.pvio); mysql->net.pvio= NULL; mysql->net.error= 1; } @@ -2117,15 +2118,12 @@ void my_set_error(MYSQL *mysql, void mysql_close_slow_part(MYSQL *mysql) { - if (mysql->net.pvio) - { - free_old_query(mysql); - mysql->status=MYSQL_STATUS_READY; /* Force command */ - mysql->options.reconnect=0; - if (mysql->net.pvio && mysql->net.buff) - ma_simple_command(mysql, COM_QUIT,NullS,0,1,0); - end_server(mysql); - } + free_old_query(mysql); + mysql->status=MYSQL_STATUS_READY; /* Force command */ + mysql->options.reconnect=0; + if (mysql->net.pvio && mysql->net.buff) + ma_simple_command(mysql, COM_QUIT,NullS,0,1,0); + end_server(mysql); } static void ma_clear_session_state(MYSQL *mysql) From 232b563dc57d731a28d11e382c60c642d5f327d3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 16 Jan 2025 20:18:10 +0100 Subject: [PATCH 2/3] CONPY-739 don't use pow() to truncate an integer it's * generic power function, arbitrary floating-point arguments * expensive * returns double while here we just need one of 1, 10, ..., 1000000. --- libmariadb/ma_stmt_codec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libmariadb/ma_stmt_codec.c b/libmariadb/ma_stmt_codec.c index ab3ec1ed..8c8ce8c2 100644 --- a/libmariadb/ma_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -1106,6 +1106,7 @@ static void convert_to_datetime(MYSQL_TIME *t, unsigned char **row, uint len, en } } +static const uint32_t sec_part_digits[]= {1000000, 100000, 10000, 1000, 100, 10, 1}; /* {{{ ps_fetch_datetime */ static @@ -1151,7 +1152,7 @@ void ps_fetch_datetime(MYSQL_BIND *r_param, const MYSQL_FIELD * field, { uint8_t decimals= (field->decimals == AUTO_SEC_PART_DIGITS) ? SEC_PART_DIGITS : field->decimals; length= sprintf(dtbuffer, "%s%02u:%02u:%02u.%0*u", (tm.neg ? "-" : ""), tm.hour, tm.minute, tm.second, - decimals, (uint32_t)(tm.second_part / pow(10, 6 - decimals))); + decimals, (uint32_t)(tm.second_part / sec_part_digits[decimals])); } else length= sprintf(dtbuffer, "%s%02u:%02u:%02u", (tm.neg ? "-" : ""), tm.hour, tm.minute, tm.second); break; @@ -1162,7 +1163,7 @@ void ps_fetch_datetime(MYSQL_BIND *r_param, const MYSQL_FIELD * field, { uint8_t decimals= (field->decimals == AUTO_SEC_PART_DIGITS) ? SEC_PART_DIGITS : field->decimals; length= sprintf(dtbuffer, "%04u-%02u-%02u %02u:%02u:%02u.%0*u", tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second, - decimals, (uint32_t)(tm.second_part / pow(10, 6 - decimals))); + decimals, (uint32_t)(tm.second_part / sec_part_digits[decimals])); } else length= sprintf(dtbuffer, "%04u-%02u-%02u %02u:%02u:%02u", tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second); break; From 7d930974c0c5588a8872f30b83d6bc429106f825 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 23 Jan 2025 23:07:32 +0100 Subject: [PATCH 3/3] CONC-751 unit.conc_connection fails with CYPHER missmatch on some builds disable the test for old gnutls --- unittest/libmariadb/connection.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unittest/libmariadb/connection.c b/unittest/libmariadb/connection.c index aff5b65f..90edc6f6 100644 --- a/unittest/libmariadb/connection.c +++ b/unittest/libmariadb/connection.c @@ -1966,7 +1966,8 @@ static int test_conc632(MYSQL *my __attribute__((unused))) return OK; } -#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) +#if defined(HAVE_GNUTLS) && GNUTLS_VERSION_NUMBER >= 0x030700 || defined(HAVE_OPENSSL) +#define HAVE_test_conc748 static int test_conc748(MYSQL *my __attribute__((unused))) { MYSQL *mysql; @@ -2048,7 +2049,7 @@ static int test_conc589(MYSQL *my) struct my_tests_st my_tests[] = { {"test_conc589", test_conc589, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, -#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) +#ifdef HAVE_test_conc748 {"test_conc748", test_conc748, TEST_CONNECTION_NONE, 0, NULL, NULL}, #endif {"test_conc632", test_conc632, TEST_CONNECTION_NONE, 0, NULL, NULL},