@@ -280,12 +280,13 @@ MySQL_dealloc(MySQL *self)
280
280
{
281
281
if (self ) {
282
282
MySQL_free_result (self );
283
- if (& self -> session )
284
- {
285
- mysql_close (& self -> session );
286
- }
283
+ mysql_close (& self -> session );
284
+
285
+ Py_DECREF (self -> charset_name );
286
+ Py_DECREF (self -> auth_plugin );
287
+
287
288
Py_TYPE (self )-> tp_free ((PyObject * )self );
288
- }
289
+ }
289
290
}
290
291
291
292
/**
@@ -358,7 +359,7 @@ MySQL_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
358
359
int
359
360
MySQL_init (MySQL * self , PyObject * args , PyObject * kwds )
360
361
{
361
- PyObject * use_unicode = NULL , * auth_plugin = NULL , * tmp , * con_timeout = NULL ;
362
+ PyObject * charset_name = NULL , * use_unicode = NULL , * auth_plugin = NULL , * tmp , * con_timeout = NULL ;
362
363
363
364
static char * kwlist []=
364
365
{
@@ -375,7 +376,7 @@ MySQL_init(MySQL *self, PyObject *args, PyObject *kwds)
375
376
"|O!O!O!O!O!O!" , kwlist ,
376
377
& PyBool_Type , & self -> buffered_at_connect ,
377
378
& PyBool_Type , & self -> raw_at_connect ,
378
- & PyStringType , & self -> charset_name ,
379
+ & PyStringType , & charset_name ,
379
380
& PyIntType , & con_timeout ,
380
381
& PyBool_Type , & use_unicode ,
381
382
& PyStringType , & auth_plugin ))
@@ -400,6 +401,12 @@ MySQL_init(MySQL *self, PyObject *args, PyObject *kwds)
400
401
}
401
402
}
402
403
404
+ if (charset_name ) {
405
+ Py_DECREF (self -> charset_name );
406
+ self -> charset_name = charset_name ;
407
+ Py_INCREF (self -> charset_name );
408
+ }
409
+
403
410
if (auth_plugin )
404
411
{
405
412
if (strcmp (PyStringAsString (auth_plugin ), "" ) == 0 )
@@ -974,7 +981,9 @@ MySQL_set_character_set(MySQL *self, PyObject *args)
974
981
return NULL ;
975
982
}
976
983
984
+ Py_DECREF (self -> charset_name );
977
985
self -> charset_name = value ;
986
+ Py_INCREF (self -> charset_name );
978
987
979
988
Py_RETURN_NONE ;
980
989
}
@@ -1740,22 +1749,17 @@ MySQL_ping(MySQL *self)
1740
1749
PyObject *
1741
1750
MySQL_convert_to_mysql (MySQL * self , PyObject * args )
1742
1751
{
1743
- PyObject * value , * new_value ;
1744
- PyObject * prepared , * quoted ;
1752
+ PyObject * prepared ;
1745
1753
int i ;
1746
1754
Py_ssize_t size ;
1747
1755
char error [100 ];
1748
- #ifndef PY3
1749
- int tmp_size ;
1750
- PyObject * numeric , * new_num ;
1751
- char * tmp ;
1752
- #endif
1753
1756
1754
1757
size = PyTuple_Size (args );
1755
1758
prepared = PyTuple_New (size );
1756
1759
1757
1760
for (i = 0 ; i < size ; i ++ ) {
1758
- value = PyTuple_GetItem (args , i );
1761
+ PyObject * value = PyTuple_GetItem (args , i );
1762
+ PyObject * new_value = NULL ;
1759
1763
1760
1764
if (value == NULL )
1761
1765
{
@@ -1772,19 +1776,23 @@ MySQL_convert_to_mysql(MySQL *self, PyObject *args)
1772
1776
if (PyIntLong_Check (value ) || PyFloat_Check (value ))
1773
1777
{
1774
1778
#ifdef PY3
1779
+ PyObject * str = PyObject_Str (value );
1775
1780
PyTuple_SET_ITEM (prepared , i ,
1776
1781
PyBytes_FromString (
1777
1782
(const char * )PyUnicode_1BYTE_DATA (
1778
- PyObject_Str (value ))));
1783
+ str )));
1784
+ Py_DECREF (str );
1779
1785
#else
1780
- numeric = PyObject_Repr (value );
1781
- tmp = PyString_AsString (numeric );
1786
+ int tmp_size ;
1787
+ PyObject * numeric = PyObject_Repr (value );
1788
+ char * tmp = PyString_AsString (numeric );
1782
1789
tmp_size = (int )PyString_Size (numeric );
1783
1790
if (tmp [tmp_size - 1 ] == 'L' )
1784
1791
{
1785
- new_num = PyString_FromStringAndSize (tmp , tmp_size );
1792
+ PyObject * new_num = PyString_FromStringAndSize (tmp , tmp_size );
1786
1793
_PyString_Resize (& new_num , tmp_size - 1 );
1787
1794
PyTuple_SET_ITEM (prepared , i , new_num );
1795
+ Py_DECREF (numeric );
1788
1796
}
1789
1797
else
1790
1798
{
@@ -1854,16 +1862,16 @@ MySQL_convert_to_mysql(MySQL *self, PyObject *args)
1854
1862
}
1855
1863
else if (PyBytes_Check (new_value ))
1856
1864
{
1857
- quoted = PyBytes_FromFormat ("'%s'" , PyBytes_AsString (new_value ));
1865
+ PyObject * quoted = PyBytes_FromFormat ("'%s'" , PyBytes_AsString (new_value ));
1858
1866
PyTuple_SET_ITEM (prepared , i , quoted );
1859
1867
#endif
1860
1868
}
1861
1869
else if (PyString_Check (new_value ))
1862
1870
{
1863
1871
#ifdef PY3
1864
- quoted = PyBytes_FromFormat ("'%s'" , PyUnicode_AS_DATA (new_value ));
1872
+ PyObject * quoted = PyBytes_FromFormat ("'%s'" , PyUnicode_AS_DATA (new_value ));
1865
1873
#else
1866
- quoted = PyString_FromFormat ("'%s'" , PyStringAsString (new_value ));
1874
+ PyObject * quoted = PyString_FromFormat ("'%s'" , PyStringAsString (new_value ));
1867
1875
#endif
1868
1876
PyTuple_SET_ITEM (prepared , i , quoted );
1869
1877
}
0 commit comments