From 099f3eb93f62a029c7d2b9f9010387b096b7b746 Mon Sep 17 00:00:00 2001 From: Laurynas Biveinis Date: Wed, 1 Jun 2016 14:54:26 +0300 Subject: [PATCH] Fix bug 81675 (mysqlbinlog does not free the existing connection before opening new remote one) If mysqlbinlog is invoked with --read-from-remote-server and several binlog file names, each file will be read with the server connection re-opened. But the existing connection is only closed on mysqlbinlog termination, not before a new connection is opened for the next file. This causes a memory leak. Fix by closing the old connection, if any, at the start of safe_connect(). --- client/mysqlbinlog.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index aa8a803..4e519cb 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1611,6 +1611,9 @@ static int parse_args(int *argc, char*** argv) */ static Exit_status safe_connect() { + /* If we are opening a new connection, close the old one first */ + if (mysql) + mysql_close(mysql); mysql= mysql_init(NULL); if (!mysql)