FFFF BUG#35425076: Fix deallocating None error · mysql/mysql-connector-python@1141d96 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1141d96

Browse files
committed
BUG#35425076: Fix deallocating None error
The patch for BUG#35233031, which removes the default authentication plugin mysql_native_password as the default replaces the variable type in the C extension to Py_None without incrementing the reference count, leading to a deallocation error when calling the connection close multiple times. This patch fixes the issue by setting the default value of the authentication plugin to PyUnicode_FromString("") instead of Py_None. Change-Id: I29314517fc55051d293f939c4e65ae58678e725a
1 parent 8203931 commit 1141d96

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ v8.1.0
1515
- WL#15672: Upgrade Python Protobuf version to 4.21.12
1616
- WL#15630: Remove Python 3.7 support
1717
- WL#15591: Improve the network module
18+
- BUG#35425076: Fix deallocating None error
1819
- BUG#35349093: Compression doesn't work with C extension API
1920
- BUG#35338384: PIP installs incompatible Connector/Python packages
2021
- BUG#35318413: Fix charset mapping for MySQL 8.1.0

src/mysql_capi.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ MySQL_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
361361
self->result = NULL;
362362
self->fields = NULL;
363363
self->use_unicode = 1;
364-
self->auth_plugin = Py_None;
364+
self->auth_plugin = PyUnicode_FromString("");
365365
self->plugin_dir = PyUnicode_FromString(".");
366366
self->converter_str_fallback = Py_False;
367367

@@ -396,7 +396,7 @@ int
396396
MySQL_init(MySQL *self, PyObject *args, PyObject *kwds)
397397
{
398398
PyObject *charset_name = NULL, *use_unicode = NULL, *auth_plugin = NULL,
399-
*plugin_dir = NULL, *tmp, *con_timeout = NULL;
399+
*plugin_dir = NULL, *con_timeout = NULL;
400400

401401
static char *kwlist[] = {"buffered", "raw", "charset_name",
402402
"connection_timeout", "use_unicode", "auth_plugin",
@@ -430,16 +430,10 @@ MySQL_init(MySQL *self, PyObject *args, PyObject *kwds)
430430
Py_INCREF(self->charset_name);
431431
}
432432

433-
if (auth_plugin) {
434-
if (strcmp(PyUnicode_AsUTF8(auth_plugin), "") == 0) {
435-
auth_plugin = Py_None;
436-
}
437-
if (auth_plugin != Py_None) {
438-
tmp = self->auth_plugin;
439-
Py_INCREF(auth_plugin);
440-
self->auth_plugin = auth_plugin;
441-
Py_XDECREF(tmp);
442-
}
433+
if (auth_plugin && strcmp(PyUnicode_AsUTF8(auth_plugin), "") != 0) {
434+
Py_DECREF(self->auth_plugin);
435+
self->auth_plugin = auth_plugin;
436+
Py_INCREF(self->auth_plugin);
443437
}
444438

445439
if (plugin_dir) {
@@ -527,12 +521,9 @@ MySQL_free_result(MySQL *self)
527521
PyObject *
528522
MySQL_consume_result(MySQL *self)
529523
{
530-
int res = 0;
531524
if (self->result) {
532525
Py_BEGIN_ALLOW_THREADS
533-
while (mysql_fetch_row(self->result)) {
534-
res++;
535-
}
526+
while (mysql_fetch_row(self->result)) {}
536527
Py_END_ALLOW_THREADS
537528
}
538529

@@ -871,8 +862,7 @@ MySQL_change_user(MySQL *self, PyObject *args, PyObject *kwds)
871862
return NULL;
872863
}
873864

874-
if (self->auth_plugin != Py_None &&
875-
strcmp(PyUnicode_AsUTF8(self->auth_plugin), "mysql_clear_password") == 0) {
865+
if (strcmp(PyUnicode_AsUTF8(self->auth_plugin), "mysql_clear_password") == 0) {
876866
abool = 1;
877867
mysql_options(&self->session, MYSQL_ENABLE_CLEARTEXT_PLUGIN, (char *)&abool);
878868
}
@@ -1296,7 +1286,7 @@ MySQL_connect(MySQL *self, PyObject *args, PyObject *kwds)
12961286
#endif
12971287
}
12981288

1299-
if (PyUnicode_Check(self->auth_plugin)) {
1289+
if (strcmp(PyUnicode_AsUTF8(self->auth_plugin), "") != 0) {
13001290
auth_plugin = PyUnicode_AsUTF8(self->auth_plugin);
13011291
mysql_options(&self->session, MYSQL_DEFAULT_AUTH, auth_plugin);
13021292
if (strcmp(auth_plugin, "sha256_password") == 0 && !ssl_enabled) {

0 commit comments

Comments
 (0)
0