From 557bdb621391c8bc6258c925c0ee7cee9df78c47 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Mon, 9 Feb 2026 02:50:20 +0500 Subject: [PATCH] Added missing iterator advancement --- lib/PgSQL_PreparedStatement.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/PgSQL_PreparedStatement.cpp b/lib/PgSQL_PreparedStatement.cpp index 3a4b9400a..d188027d4 100644 --- a/lib/PgSQL_PreparedStatement.cpp +++ b/lib/PgSQL_PreparedStatement.cpp @@ -290,23 +290,19 @@ void PgSQL_STMT_Manager::ref_count_client___purge_stmts_if_needed() noexcept { // use_count() == 1 indicates that only map_stmt_hash_to_info holds a reference, // meaning there are no other references (from client or server) to this prepared statement. // So we can safely remove this entry. - if (global_stmt_info.use_count() == 1) { - // Use memory_order_acquire to see latest refcount modifications - // Since write lock prevents NEW references, only existing raw pointers can race - if (global_stmt_info->ref_count_client.load(std::memory_order_acquire) == 0 && - global_stmt_info->ref_count_server.load(std::memory_order_acquire) == 0) { - - // Atomic counters - num_stmt_with_ref_client_count_zero.fetch_sub(1, std::memory_order_relaxed); - num_stmt_with_ref_server_count_zero.fetch_sub(1, std::memory_order_relaxed); - - // Free ID - free_stmt_ids.push(global_stmt_info->statement_id); - - // Safe erase from map while iterating - it = map_stmt_hash_to_info.erase(it); - remaining_removals--; - } + if (global_stmt_info.use_count() == 1 && + global_stmt_info->ref_count_client.load(std::memory_order_acquire) == 0 && // Use memory_order_acquire to see latest refcount modifications + global_stmt_info->ref_count_server.load(std::memory_order_acquire) == 0) { // Since write lock prevents NEW references, only existing raw pointers can race + // Atomic counters + num_stmt_with_ref_client_count_zero.fetch_sub(1, std::memory_order_relaxed); + num_stmt_with_ref_server_count_zero.fetch_sub(1, std::memory_order_relaxed); + + // Free ID + free_stmt_ids.push(global_stmt_info->statement_id); + + // Safe erase from map while iterating + it = map_stmt_hash_to_info.erase(it); + remaining_removals--; } else { ++it; }