Skip to content

Commit

Permalink
db_mysql: Do not read freed PKG memory after 1st failed reconnect
Browse files Browse the repository at this point in the history
During db_mysql_connect(), make sure to reset the "init" status after
free'ing ptr->con.  Per MySQL 5.7 docs on mysql_close():

    "Closes a previously opened connection.
	... Do not use the handler after it has been closed."

(cherry picked from commit d616ed3)
  • Loading branch information
liviuchircu committed Dec 7, 2022
1 parent 8e4794a commit 2f26942
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/db_mysql/my_con.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ int db_mysql_connect(struct my_con* ptr)
LM_ERR("TLS domain: %.*s not found\n",
tls_domain_name->len, tls_domain_name->s);
mysql_close(ptr->con);
ptr->init = 0;
return -1;
}
}
Expand Down Expand Up @@ -121,6 +122,7 @@ int db_mysql_connect(struct my_con* ptr)
LM_ERR("driver error(%d): %s\n",
mysql_errno(ptr->con), mysql_error(ptr->con));
mysql_close(ptr->con);
ptr->init = 0;
return -1;
}

Expand Down Expand Up @@ -196,7 +198,8 @@ void db_mysql_free_connection(struct pool_con* con)
if (_c->res) mysql_free_result(_c->res);
if (_c->id) free_db_id(_c->id);
if (_c->con) {
mysql_close(_c->con);
if (_c->init)
mysql_close(_c->con);
pkg_free(_c->con);
}
pkg_free(_c);
Expand Down

0 comments on commit 2f26942

Please sign in to comment.