Added missing iterator advancement

pull/5353/head
Rahim Kanji 3 months ago
parent 267b24e17f
commit 557bdb6213

@ -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;
}

Loading…
Cancel
Save