mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +08:00
memory leak in ConnectionObject_Initialize when mysql_real_connect fails (#350)
We can't set open=0 after we mysql_init or dealloc will not cleanup the memory. Also if mysql_init returns NULL we are out of memory and shouldn't set open=1, or we could segfault in dealloc if we didn't seg before that.
This commit is contained in:
@ -444,8 +444,12 @@ _mysql_ConnectionObject_Initialize(
|
||||
_stringsuck(cipher, value, ssl);
|
||||
}
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS ;
|
||||
conn = mysql_init(&(self->connection));
|
||||
if (!conn) {
|
||||
PyErr_SetNone(PyExc_MemoryError);
|
||||
return -1;
|
||||
}
|
||||
Py_BEGIN_ALLOW_THREADS ;
|
||||
self->open = 1;
|
||||
if (connect_timeout) {
|
||||
unsigned int timeout = connect_timeout;
|
||||
@ -497,7 +501,6 @@ _mysql_ConnectionObject_Initialize(
|
||||
|
||||
if (!conn) {
|
||||
_mysql_Exception(self);
|
||||
self->open = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user