Skip to content

Commit

Permalink
Merge pull request #3205 from sysown/v2.0.16-3204
Browse files Browse the repository at this point in the history
Closes #3204: Fix several memory leaks detected by valgrind
  • Loading branch information
renecannao authored Dec 20, 2020
2 parents 4d2cbd5 + bb1ceb5 commit 209ebb9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
38 changes: 26 additions & 12 deletions deps/mariadb-client-library/mariadb_lib.c.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@@ -1515,9 +1515,16 @@
diff --git libmariadb/mariadb_lib.c libmariadb/mariadb_lib.c
index d43b68c..05fd121 100644
--- libmariadb/mariadb_lib.c
+++ libmariadb/mariadb_lib.c
@@ -1515,9 +1515,16 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,

mysql->client_flag= client_flag;

Expand All @@ -15,7 +19,7 @@

if (mysql->client_flag & CLIENT_COMPRESS)
net->compress= 1;
@@ -1568,6 +1575,15 @@
@@ -1568,6 +1575,15 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
return(mysql);

error:
Expand All @@ -31,7 +35,7 @@
/* Free alloced memory */
end_server(mysql);
/* only free the allocated memory, user needs to call mysql_close */
@@ -1647,7 +1663,7 @@
@@ -1647,7 +1663,7 @@ my_bool STDCALL mariadb_reconnect(MYSQL *mysql)
if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
mysql->db, mysql->port, mysql->unix_socket,
mysql->client_flag | CLIENT_REMEMBER_OPTIONS) ||
Expand All @@ -40,23 +44,23 @@
{
if (ctxt)
my_context_install_suspend_resume_hook(ctxt, NULL, NULL);
@@ -1693,6 +1709,7 @@
@@ -1693,6 +1709,7 @@ void ma_invalidate_stmts(MYSQL *mysql, const char *function_name)
{
if (mysql->stmts)
{
+/*
LIST *li_stmt= mysql->stmts;

for (; li_stmt; li_stmt= li_stmt->next)
@@ -1701,6 +1718,7 @@
@@ -1701,6 +1718,7 @@ void ma_invalidate_stmts(MYSQL *mysql, const char *function_name)
stmt->mysql= NULL;
SET_CLIENT_STMT_ERROR(stmt, CR_STMT_CLOSED, SQLSTATE_UNKNOWN, function_name);
}
+*/
mysql->stmts= NULL;
}
}
@@ -1970,6 +1988,33 @@
@@ -1970,6 +1988,44 @@ mysql_close(MYSQL *mysql)
return;
}

Expand All @@ -78,6 +82,17 @@
+ mysql_close_options(mysql);
+ mysql->host_info=mysql->user=mysql->passwd=mysql->db=0;
+
+ // fix for proxysql bug #3204
+ if (mysql->net.extension) {
+ free(mysql->net.extension);
+ mysql->net.extension=NULL;
+ }
+
+ if (mysql->extension) {
+ free(mysql->extension);
+ mysql->extension=NULL;
+ }
+
+ /* Clear pointers for better safety */
+ bzero((char*) &mysql->options,sizeof(mysql->options));
+ mysql->net.pvio= 0;
Expand All @@ -90,7 +105,7 @@

/**************************************************************************
** Do a query. If query returned rows, free old rows.
@@ -2036,6 +2081,8 @@
@@ -2036,6 +2092,8 @@ int ma_read_ok_packet(MYSQL *mysql, uchar *pos, ulong length)
old_pos= pos;
si_type= (enum enum_session_state_type)net_field_length(&pos);
switch(si_type) {
Expand All @@ -99,7 +114,7 @@
case SESSION_TRACK_SCHEMA:
case SESSION_TRACK_STATE_CHANGE:
case SESSION_TRACK_TRANSACTION_CHARACTERISTICS:
@@ -3474,18 +3521,27 @@
@@ -3474,18 +3532,27 @@ void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs)
mariadb_get_charset_info(mysql, cs);
}

Expand All @@ -113,15 +128,14 @@
goto error;

- if ((cs= mysql_find_charset_name(csname)))
- {
- char buff[64];
+ if (csname) {
+ cs = mysql_find_charset_name(csname);
+ } else {
+ cs = mysql_find_charset_nr(charsetnr);
+ }
+ if (cs)
+ {
{
- char buff[64];
+ char buff[128];
+ if (csname) { // default behavior
+ snprintf(buff, 127, "SET NAMES %s", cs->csname);
Expand All @@ -133,7 +147,7 @@
if (!mysql_real_query(mysql, buff, (unsigned long)strlen(buff)))
{
mysql->charset= cs;
@@ -3494,6 +3550,7 @@
@@ -3494,6 +3561,7 @@ int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname)
}

error:
Expand Down
3 changes: 3 additions & 0 deletions lib/ProxySQL_Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9941,6 +9941,7 @@ void ProxySQL_Admin::save_mysql_servers_runtime_to_database(bool _runtime) {
sqlite3_finalize(statement);
}
if(resultset) delete resultset;
resultset = NULL;

// dump mysql_galera_hostgroups
if (_runtime) {
Expand Down Expand Up @@ -9983,6 +9984,8 @@ void ProxySQL_Admin::save_mysql_servers_runtime_to_database(bool _runtime) {
}
sqlite3_finalize(statement);
}
if(resultset) delete resultset;
resultset = NULL;

// dump mysql_aws_aurora_hostgroups

Expand Down

0 comments on commit 209ebb9

Please sign in to comment.