Skip to content

Commit 446f580

Browse files
committed
avoid a possible double-free at the cost of a possible leak
1 parent 6a3a708 commit 446f580

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Modules/_sqlite/cursor.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,8 +1367,15 @@ 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);
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+
}
13721379
return NULL;
13731380
}
13741381

0 commit comments

Comments
 (0)