From 0a65c3d34a4f7c6bf5ed88fe78d4b7f24dc71cdd Mon Sep 17 00:00:00 2001 From: Robert Klink Date: Wed, 31 Jul 2024 14:34:41 +0200 Subject: [PATCH] unix-ffi/sqlite3: Fix statements not being finalized. Currently, statements are only finalized upon a call to Cursor.close(). However, in Cursor.execute() new statements get created without the previous statements being finalized, causing those to get leaked, preventing the database from being closed. The fix addresses this by finalizing the previous statement if it exists. Signed-off-by: Robert Klink --- unix-ffi/sqlite3/sqlite3.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/unix-ffi/sqlite3/sqlite3.py b/unix-ffi/sqlite3/sqlite3.py index 1f8bdd6c..24175ec1 100644 --- a/unix-ffi/sqlite3/sqlite3.py +++ b/unix-ffi/sqlite3/sqlite3.py @@ -84,6 +84,11 @@ class Cursor: self.stmnt = None def execute(self, sql, params=None): + if self.stmnt: + # If there is an existing statement, finalize that to free it + res = sqlite3_finalize(self.stmnt) + check_error(self.h, res) + if params: params = [quote(v) for v in params] sql = sql % tuple(params)