Skip to content

Commit 586652a

Browse files
committed
BUG#36702939: connection_cext has a memory leak in the python mysql-connector
With this patch, the connection API command `get_rows()` of the C-extension implementation stops leaking memory when working with and without prepared statements. Change-Id: I7251eb19c9901c56694dd38d8a8c19885cd5f24b
1 parent f08eaaa commit 586652a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ v9.2.0
1414
- WL#16381: Add support for read and write timeouts
1515
- WL#16285: Remake Multi Statement Execution
1616
- BUG#37145655: MySQL Connector/Python Configuration Files RCE
17+
- BUG#36702939: connection_cext has a memory leak in the python mysql-connector
1718
- BUG#36922645: Option `connection_timeout` is overwritten and works as "query" timeout instead
1819
- BUG#36126909: "Unread result found" exception/bad MySQLCursor.statement when query text contains code comments
1920
- BUG#35810050: Executing multiple statements fails when importing Sakila

mysql-connector-python/src/mysql_capi.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,11 +2797,18 @@ MySQL_fetch_row(MySQL *self)
27972797
else {
27982798
if (field_flags & SET_FLAG) {
27992799
if (!strlen(row[i])) {
2800+
Py_XDECREF(value);
28002801
value = PySet_New(NULL);
28012802
}
28022803
else {
2803-
value =
2804-
PySet_New(PyUnicode_Split(value, PyUnicode_FromString(","), -1));
2804+
PyObject *sep = PyUnicode_FromString(",");
2805+
PyObject *iterable = PyUnicode_Split(value, sep, -1);
2806+
2807+
Py_XDECREF(value);
2808+
value = PySet_New(iterable);
2809+
2810+
Py_XDECREF(sep);
2811+
Py_XDECREF(iterable);
28052812
}
28062813
if (!value) {
28072814
goto error;
@@ -3764,6 +3771,7 @@ MySQLPrepStmt_fetch_row(MySQLPrepStmt *self)
37643771
}
37653772
Py_XDECREF(mod_decimal);
37663773
}
3774+
Py_XDECREF(obj);
37673775
break;
37683776
/* MYSQL_TYPE_CHAR, MYSQL_TYPE_VARCHAR, MYSQL_TYPE_STRING, */
37693777
/* MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_GEOMETRY, MYSQL_TYPE_BLOB */
@@ -3788,7 +3796,7 @@ MySQLPrepStmt_fetch_row(MySQLPrepStmt *self)
37883796
}
37893797

37903798
for (token = strtok_r(PyBytes_AsString(obj), ",", &rest); token != NULL;
3791-
token = strtok_r(NULL, ",", &rest)) {
3799+
token = strtok_r(NULL, ",", &rest)) {
37923800
PyObject *us = PyUnicode_FromString(token);
37933801
PySet_Add(set, us);
37943802
Py_DECREF(us);

0 commit comments

Comments
 (0)