From 53004814bc22a0c6af86d03ae19bda64a9b5a42a Mon Sep 17 00:00:00 2001 From: Vilnis Termanis Date: Thu, 10 May 2018 22:20:44 +0100 Subject: [PATCH] Fix reference leaks when converting int/long/float (to mysql) --- src/mysql_capi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mysql_capi.c b/src/mysql_capi.c index c8839a8..c51e0f3 100644 --- a/src/mysql_capi.c +++ b/src/mysql_capi.c @@ -1751,10 +1751,12 @@ MySQL_convert_to_mysql(MySQL *self, PyObject *args) if (PyIntLong_Check(value) || PyFloat_Check(value)) { #ifdef PY3 + new_value = PyObject_Str(value); PyTuple_SET_ITEM(prepared, i, PyBytes_FromString( (const char *)PyUnicode_1BYTE_DATA( - PyObject_Str(value)))); + new_value))); + Py_CLEAR(new_value); #else numeric= PyObject_Repr(value); tmp= PyString_AsString(numeric); @@ -1764,6 +1766,7 @@ MySQL_convert_to_mysql(MySQL *self, PyObject *args) new_num= PyString_FromStringAndSize(tmp, tmp_size); _PyString_Resize(&new_num, tmp_size - 1); PyTuple_SET_ITEM(prepared, i, new_num); + Py_CLEAR(numeric); } else {