summaryrefslogtreecommitdiff
path: root/source/n/dovecot/fix-mysql-double-free.patch
blob: 47842f706d52b6856912b463617563263b5732b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
From 3c5101ffdd2a8115e03ed7180d53578765dea4c9 Mon Sep 17 00:00:00 2001
From: Aki Tuomi <aki.tuomi@dovecot.fi>
Date: Tue, 4 Dec 2018 14:40:04 +0200
Subject: [PATCH] driver-mysql: Avoid double-closing MySQL connection

Fixes double-free
---
 src/lib-sql/driver-mysql.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/lib-sql/driver-mysql.c b/src/lib-sql/driver-mysql.c
index c87e825e4b..5dd1c3124f 100644
--- a/src/lib-sql/driver-mysql.c
+++ b/src/lib-sql/driver-mysql.c
@@ -173,7 +173,9 @@ static int driver_mysql_connect(struct sql_db *_db)
 static void driver_mysql_disconnect(struct sql_db *_db)
 {
 	struct mysql_db *db = (struct mysql_db *)_db;
-	mysql_close(db->mysql);
+	if (db->mysql != NULL)
+		mysql_close(db->mysql);
+	db->mysql = NULL;
 }
 
 static int driver_mysql_parse_connect_string(struct mysql_db *db,
@@ -311,7 +313,9 @@ static void driver_mysql_deinit_v(struct sql_db *_db)
 	_db->no_reconnect = TRUE;
 	sql_db_set_state(&db->api, SQL_DB_STATE_DISCONNECTED);
 
-	mysql_close(db->mysql);
+	if (db->mysql != NULL)
+		mysql_close(db->mysql);
+	db->mysql = NULL;
 
 	sql_connection_log_finished(_db);
 	event_unref(&_db->event);