@@ -195,16 +195,20 @@ MrdbPool_initialize(MrdbPool *self, PyObject *args, PyObject *kwargs)
195
195
goto error ;
196
196
}
197
197
clock_gettime (CLOCK_MONOTONIC_RAW , & self -> connection [i ]-> last_used );
198
- Py_INCREF (self -> connection [i ]);
199
198
self -> connection [i ]-> pool = self ;
200
199
}
201
200
self -> connection_cnt = self -> pool_size ;
202
201
}
203
202
PyDict_SetItemString (cnx_pool , self -> pool_name , (PyObject * )self );
204
- Py_INCREF (self );
203
+
204
+ Py_XDECREF (conn_kwargs );
205
+ Py_XDECREF (pool_kwargs );
205
206
206
207
return 0 ;
207
208
error :
209
+ Py_XDECREF (conn_kwargs );
210
+ Py_XDECREF (pool_kwargs );
211
+
208
212
if (self -> connection )
209
213
{
210
214
for (i = 0 ; i < self -> pool_size ; i ++ )
@@ -300,10 +304,11 @@ MrdbPool_Type =
300
304
void
301
305
MrdbPool_dealloc (MrdbPool * self )
302
306
{
303
- PyObject_GC_UnTrack (self );
304
- MrdbPool_close (self );
305
-
306
- Py_TYPE (self )-> tp_free ((PyObject * )self );
307
+ if (self )
308
+ {
309
+ MrdbPool_close (self );
310
+ Py_TYPE (self )-> tp_free ((PyObject * )self );
311
+ }
307
312
}
308
313
/* }}} */
309
314
@@ -366,6 +371,7 @@ MrdbPool_getconnection(MrdbPool *self)
366
371
pthread_mutex_unlock (& self -> lock );
367
372
if (conn )
368
373
{
374
+ Py_INCREF (conn );
369
375
return (PyObject * )conn ;
370
376
}
371
377
mariadb_throw_exception (NULL , Mariadb_PoolError , 0 ,
@@ -526,17 +532,21 @@ MrdbPool_close(MrdbPool *self)
526
532
MARIADB_FREE_MEM (self -> connection );
527
533
self -> connection = NULL ;
528
534
}
535
+
529
536
self -> pool_size = 0 ;
530
537
531
538
if (self -> pool_name )
532
539
{
533
- if (PyDict_Contains (cnx_pool , PyUnicode_FromString (self -> pool_name )))
540
+ PyObject * obj = PyUnicode_FromString (self -> pool_name );
541
+ if (PyDict_Contains (cnx_pool , obj ))
534
542
{
535
543
PyDict_DelItemString (cnx_pool , self -> pool_name );
536
544
}
537
545
MARIADB_FREE_MEM (self -> pool_name );
538
546
self -> pool_name = 0 ;
547
+ Py_DECREF (obj );
539
548
}
549
+ Py_XDECREF (self -> configuration );
540
550
pthread_mutex_unlock (& self -> lock );
541
551
pthread_mutex_destroy (& self -> lock );
542
552
Py_INCREF (Py_None );
0 commit comments