Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b66971e

Browse filesBrowse files
friedmethane
authored andcommitted
memory leak in ConnectionObject_Initialize when mysql_real_connect fails (PyMySQL#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.
1 parent e04c597 commit b66971e
Copy full SHA for b66971e

File tree

Expand file treeCollapse file tree

1 file changed

+5
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-2
lines changed

‎MySQLdb/_mysql.c

Copy file name to clipboardExpand all lines: MySQLdb/_mysql.c
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,12 @@ _mysql_ConnectionObject_Initialize(
444444
_stringsuck(cipher, value, ssl);
445445
}
446446

447-
Py_BEGIN_ALLOW_THREADS ;
448447
conn = mysql_init(&(self->connection));
448+
if (!conn) {
449+
PyErr_SetNone(PyExc_MemoryError);
450+
return -1;
451+
}
452+
Py_BEGIN_ALLOW_THREADS ;
449453
self->open = 1;
450454
if (connect_timeout) {
451455
unsigned int timeout = connect_timeout;
@@ -497,7 +501,6 @@ _mysql_ConnectionObject_Initialize(
497501

498502
if (!conn) {
499503
_mysql_Exception(self);
500-
self->open = 0;
501504
return -1;
502505
}
503506

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.