From ea80e8f07a803307778fa43ae8f70f28f39a4a5b Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Mon, 17 Dec 2018 19:27:54 +0900 Subject: [PATCH] Fix error handling of mysql_real_connect (#317) Fixes #316 --- MySQLdb/_mysql.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MySQLdb/_mysql.c b/MySQLdb/_mysql.c index 5ae6652..cf4566d 100644 --- a/MySQLdb/_mysql.c +++ b/MySQLdb/_mysql.c @@ -446,6 +446,7 @@ _mysql_ConnectionObject_Initialize( Py_BEGIN_ALLOW_THREADS ; conn = mysql_init(&(self->connection)); + self->open = 1; if (connect_timeout) { unsigned int timeout = connect_timeout; mysql_options(&(self->connection), MYSQL_OPT_CONNECT_TIMEOUT, @@ -496,6 +497,7 @@ _mysql_ConnectionObject_Initialize( if (!conn) { _mysql_Exception(self); + self->open = 0; return -1; } @@ -515,7 +517,6 @@ _mysql_ConnectionObject_Initialize( be done here. tp_dealloc still needs to call PyObject_GC_UnTrack(), however. */ - self->open = 1; return 0; }