@@ -226,27 +226,27 @@ pysqlite_connection_init_impl(pysqlite_Connection *self,
226
226
pysqlite_state * state = pysqlite_get_state_by_type (Py_TYPE (self ));
227
227
if (rc != SQLITE_OK ) {
228
228
_pysqlite_seterror (state , db );
229
- return -1 ;
229
+ goto error ;
230
230
}
231
231
232
232
// Create LRU statement cache; returns a new reference.
233
233
PyObject * statement_cache = new_statement_cache (self , state , cache_size );
234
234
if (statement_cache == NULL ) {
235
- return -1 ;
235
+ goto error ;
236
236
}
237
237
238
238
/* Create lists of weak references to cursors and blobs */
239
239
PyObject * cursors = PyList_New (0 );
240
240
if (cursors == NULL ) {
241
- Py_XDECREF (statement_cache );
242
- return -1 ;
241
+ Py_DECREF (statement_cache );
242
+ goto error ;
243
243
}
244
244
245
245
PyObject * blobs = PyList_New (0 );
246
246
if (blobs == NULL ) {
247
- Py_XDECREF (statement_cache );
248
- Py_XDECREF (cursors );
249
- return -1 ;
247
+ Py_DECREF (statement_cache );
248
+ Py_DECREF (cursors );
249
+ goto error ;
250
250
}
251
251
252
252
// Init connection state members.
@@ -279,11 +279,18 @@ pysqlite_connection_init_impl(pysqlite_Connection *self,
279
279
self -> NotSupportedError = state -> NotSupportedError ;
280
280
281
281
if (PySys_Audit ("sqlite3.connect/handle" , "O" , self ) < 0 ) {
282
- return -1 ;
282
+ return -1 ; // Don't goto error; at this point, dealloc will clean up.
283
283
}
284
284
285
285
self -> initialized = 1 ;
286
286
return 0 ;
287
+
288
+ error :
289
+ // There are no statements or other SQLite objects attached to the
290
+ // database, so sqlite3_close() should always return SQLITE_OK.
291
+ rc = sqlite3_close (db );
292
+ assert (rc == SQLITE_OK ), rc ;
293
+ return -1 ;
287
294
}
288
295
289
296
#define VISIT_CALLBACK_CONTEXT (ctx ) \
0 commit comments