Skip to content

Commit 7f19dc9

Browse files
committed
Don't leak the MYSQL connection handle if there was an exception earlier
The function `disconnect_and_raise` set connected = 0, which prevented freeing the MYSQL connection handle. Switch to simply checking whether the pointer to MYSQL handle is NULL or not before freeing it. Thanks to Chris Bandy for noticing this problem while working on Client#close.
1 parent 9c27b20 commit 7f19dc9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

ext/mysql2/client.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,13 @@ static VALUE invalidate_fd(int clientfd)
209209
#endif /* _WIN32 */
210210

211211
static void *nogvl_close(void *ptr) {
212-
mysql_client_wrapper *wrapper;
213-
wrapper = ptr;
214-
if (wrapper->connected) {
215-
MARK_CONN_INACTIVE(self);
216-
wrapper->connected = 0;
212+
mysql_client_wrapper *wrapper = ptr;
213+
214+
if (wrapper->client) {
217215
mysql_close(wrapper->client);
216+
wrapper->client = NULL;
217+
wrapper->connected = 0;
218+
wrapper->active_thread = Qnil;
218219
}
219220

220221
return NULL;

0 commit comments

Comments
 (0)