Improve statement finalization and cleanup (#20433)
Stelios Fragkakis committed
Jun 6, 2025 at 16:56 UTC
aeaf2e01b143ef3f21ef4c890e39213156f3ae17
1 file changed
+4
-2
src/database/sqlite/sqlite_functions.c
+4
-2
@@ -175,9 +175,12 @@ static void finalize_and_free_stmt_list(struct stmt_pool_s *stmt_list)
175
176
int max_keys = stmt_list->count;
177
for (int i = 0; i < max_keys; i++) {
178
+ if (!stmt_list->stmt[i])
179
+ continue;
180
int rc = sqlite3_finalize((sqlite3_stmt *)stmt_list->stmt[i]);
181
if (unlikely(rc != SQLITE_OK))
182
error_report("Failed to finalize statement, rc = %d", rc);
183
+ stmt_list->stmt[i] = NULL;
184
}
185
freez(stmt_list->name);
186
freez(stmt_list);
@@ -188,11 +191,10 @@ void finalize_self_prepared_sql_statements()
191
{
192
if (!thread_stmt_pool)
193
return;
191
-
194
+ spinlock_lock(&JudyL_thread_stmt_lock);
195
Word_t thread_id = thread_stmt_pool->thread_id;
196
finalize_and_free_stmt_list(thread_stmt_pool);
197
thread_stmt_pool = NULL;
195
- spinlock_lock(&JudyL_thread_stmt_lock);
198
(void) JudyLDel(&JudyL_thread_stmt_pool, thread_id, PJE0);
199
spinlock_unlock(&JudyL_thread_stmt_lock);
200
}