Skip to content

Commit ea80e8f

Browse files
authored
Fix error handling of mysql_real_connect (PyMySQL#317)
Fixes PyMySQL#316
1 parent ecf6d53 commit ea80e8f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

MySQLdb/_mysql.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ _mysql_ConnectionObject_Initialize(
446446

447447
Py_BEGIN_ALLOW_THREADS ;
448448
conn = mysql_init(&(self->connection));
449+
self->open = 1;
449450
if (connect_timeout) {
450451
unsigned int timeout = connect_timeout;
451452
mysql_options(&(self->connection), MYSQL_OPT_CONNECT_TIMEOUT,
@@ -496,6 +497,7 @@ _mysql_ConnectionObject_Initialize(
496497

497498
if (!conn) {
498499
_mysql_Exception(self);
500+
self->open = 0;
499501
return -1;
500502
}
501503

@@ -515,7 +517,6 @@ _mysql_ConnectionObject_Initialize(
515517
be done here. tp_dealloc still needs to call PyObject_GC_UnTrack(),
516518
however.
517519
*/
518-
self->open = 1;
519520
return 0;
520521
}
521522

0 commit comments

Comments
 (0)