@@ -149,7 +149,7 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
149
149
static void free_callback_context (callback_context * ctx );
150
150
static void set_callback_context (callback_context * * ctx_pp ,
151
151
callback_context * ctx );
152
- static void connection_close (pysqlite_Connection * self );
152
+ static int connection_close (pysqlite_Connection * self );
153
153
PyObject * _pysqlite_query_execute (pysqlite_Cursor * , int , PyObject * , PyObject * );
154
154
155
155
static PyObject *
@@ -249,7 +249,9 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
249
249
if (self -> initialized ) {
250
250
PyTypeObject * tp = Py_TYPE (self );
251
251
tp -> tp_clear ((PyObject * )self );
252
- connection_close (self );
252
+ if (connection_close (self ) < 0 ) {
253
+ return -1 ;
254
+ }
253
255
self -> initialized = 0 ;
254
256
}
255
257
@@ -439,7 +441,7 @@ remove_callbacks(sqlite3 *db)
439
441
(void )sqlite3_set_authorizer (db , NULL , NULL );
440
442
}
441
443
442
- static void
444
+ static int
443
445
connection_close (pysqlite_Connection * self )
444
446
{
445
447
if (self -> db ) {
@@ -452,7 +454,7 @@ connection_close(pysqlite_Connection *self)
452
454
remove_callbacks (self -> db );
453
455
}
454
456
if (connection_exec_stmt (self , "ROLLBACK" ) < 0 ) {
455
- PyErr_WriteUnraisable (( PyObject * ) self ) ;
457
+ return -1 ;
456
458
}
457
459
}
458
460
@@ -466,17 +468,21 @@ connection_close(pysqlite_Connection *self)
466
468
assert (rc == SQLITE_OK ), (void )rc ;
467
469
Py_END_ALLOW_THREADS
468
470
}
471
+ return 0 ;
469
472
}
470
473
471
474
static void
472
- connection_dealloc (pysqlite_Connection * self )
475
+ connection_dealloc (PyObject * self )
473
476
{
477
+ pysqlite_Connection * con = (pysqlite_Connection * )self ;
474
478
PyTypeObject * tp = Py_TYPE (self );
475
479
PyObject_GC_UnTrack (self );
476
- tp -> tp_clear (( PyObject * ) self );
480
+ tp -> tp_clear (self );
477
481
478
482
/* Clean up if user has not called .close() explicitly. */
479
- connection_close (self );
483
+ if (connection_close (con ) < 0 ) {
484
+ PyErr_WriteUnraisable ((PyObject * )self );
485
+ }
480
486
481
487
tp -> tp_free (self );
482
488
Py_DECREF (tp );
@@ -625,7 +631,9 @@ pysqlite_connection_close_impl(pysqlite_Connection *self)
625
631
626
632
pysqlite_close_all_blobs (self );
627
633
Py_CLEAR (self -> statement_cache );
628
- connection_close (self );
634
+ if (connection_close (self ) < 0 ) {
635
+ return NULL ;
636
+ }
629
637
630
638
Py_RETURN_NONE ;
631
639
}
0 commit comments