File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -1367,12 +1367,18 @@ pysqlite_cursor_close_impl(pysqlite_Cursor *self)
13671367 return NULL ;
13681368 }
13691369
1370- if (self -> statement && stmt_reset (self -> statement ) != SQLITE_OK ) {
1371- cursor_cannot_reset_stmt_error (self , 0 );
1372- return NULL ;
1370+ if (self -> statement ) {
1371+ int rc = stmt_reset (self -> statement );
1372+ // Force self->statement to be NULL even if stmt_reset() may have
1373+ // failed to avoid a possible double-free if someone calls close()
1374+ // twice as a leak here would be better than a double-free.
1375+ Py_CLEAR (self -> statement );
1376+ if (rc != SQLITE_OK ) {
1377+ cursor_cannot_reset_stmt_error (self , 0 );
1378+ return NULL ;
1379+ }
13731380 }
13741381
1375- Py_CLEAR (self -> statement );
13761382 self -> closed = 1 ;
13771383
13781384 Py_RETURN_NONE ;
You can’t perform that action at this time.
0 commit comments