diff --git a/src/mysql_capi.c b/src/mysql_capi.c index c8839a8..78d2eb9 100644 --- a/src/mysql_capi.c +++ b/src/mysql_capi.c @@ -1217,11 +1217,11 @@ MySQL_connect(MySQL *self, PyObject *args, PyObject *kwds) #else { char* c_password; + PyObject* u_password= NULL; if (PyUnicode_Check(password)) { - PyObject* u_password= PyUnicode_AsUTF8String(password); + u_password= PyUnicode_AsUTF8String(password); c_password= PyString_AsString(u_password); - Py_DECREF(u_password); } else { @@ -1229,6 +1229,7 @@ MySQL_connect(MySQL *self, PyObject *args, PyObject *kwds) } res= mysql_real_connect(&self->session, host, user, c_password, database, port, unix_socket, client_flags); + if (u_password != NULL) Py_DECREF(u_password); } #endif