@@ -530,10 +530,12 @@ _mysql_ConnectionObject_Initialize(
530
530
PyObject * ssl = NULL ;
531
531
#if HAVE_OPENSSL
532
532
char * key = NULL , * cert = NULL , * ca = NULL ,
533
- * capath = NULL , * cipher = NULL ;
533
+ * capath = NULL , * cipher = NULL ;
534
+ PyObject * ssl_keepref [5 ] = {};
535
+ int n_ssl_keepref = 0 ;
534
536
#endif
535
537
char * host = NULL , * user = NULL , * passwd = NULL ,
536
- * db = NULL , * unix_socket = NULL ;
538
+ * db = NULL , * unix_socket = NULL ;
537
539
unsigned int port = 0 ;
538
540
unsigned int client_flag = 0 ;
539
541
static char * kwlist [] = { "host" , "user" , "passwd" , "db" , "port" ,
@@ -586,11 +588,11 @@ _mysql_ConnectionObject_Initialize(
586
588
587
589
#ifdef IS_PY3K
588
590
#define _stringsuck (d ,t ,s ) {t=PyMapping_GetItemString(s,#d);\
589
- if(t){d=PyUnicode_AsUTF8(t);Py_DECREF(t) ;}\
591
+ if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t ;}\
590
592
PyErr_Clear();}
591
593
#else
592
594
#define _stringsuck (d ,t ,s ) {t=PyMapping_GetItemString(s,#d);\
593
- if(t){d=PyString_AsString(t);Py_DECREF(t) ;}\
595
+ if(t){d=PyString_AsString(t);ssl_keepref[n_ssl_keepref++]=t ;}\
594
596
PyErr_Clear();}
595
597
#endif
596
598
@@ -645,22 +647,32 @@ _mysql_ConnectionObject_Initialize(
645
647
mysql_options (& (self -> connection ), MYSQL_OPT_LOCAL_INFILE , (char * ) & local_infile );
646
648
647
649
#if HAVE_OPENSSL
648
- if (ssl )
649
- mysql_ssl_set (& (self -> connection ),
650
- key , cert , ca , capath , cipher );
650
+ if (ssl ) {
651
+ mysql_ssl_set (& (self -> connection ), key , cert , ca , capath , cipher );
652
+ }
651
653
#endif
652
654
653
655
conn = mysql_real_connect (& (self -> connection ), host , user , passwd , db ,
654
656
port , unix_socket , client_flag );
655
657
656
658
Py_END_ALLOW_THREADS ;
657
659
660
+ #if HAVE_OPENSSL
661
+ if (ssl ) {
662
+ int i ;
663
+ for (i = 0 ; i < n_ssl_keepref ; i ++ ) {
664
+ Py_DECREF (ssl_keepref [i ]);
665
+ ssl_keepref [i ] = NULL ;
666
+ }
667
+ }
668
+ #endif
669
+
658
670
if (!conn ) {
659
671
_mysql_Exception (self );
660
672
return -1 ;
661
673
}
662
674
663
- /* Internal references to python-land objects */
675
+ /* Internal references to python-land objects */
664
676
if (!conv )
665
677
conv = PyDict_New ();
666
678
else
0 commit comments