From fdbea2a32e213e4aaa04330272ea1172ada2f131 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Fri, 13 Feb 2026 11:31:26 +0000 Subject: [PATCH] Fix uninitialized memory in Command_Counter::_counters Replace _counters{} initialization syntax with explicit memset() to ensure the _counters array is properly zero-initialized. The _counters{} syntax may not reliably zero-initialize arrays in all compiler implementations, causing Valgrind to report use of uninitialized values when add_and_reset() reads from the array. Also remove the safety checks added previously since the root cause is now properly fixed. --- include/Command_Counter.h | 5 ++--- lib/PgSQL_Query_Processor.cpp | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/Command_Counter.h b/include/Command_Counter.h index 9b790e697..c832a4ae7 100644 --- a/include/Command_Counter.h +++ b/include/Command_Counter.h @@ -3,10 +3,9 @@ class Command_Counter { public: - Command_Counter(int cmd_idx, int col_count, char** cmd_desc) : _counters{}, _total_time(0), _cmd_idx(cmd_idx), + Command_Counter(int cmd_idx, int col_count, char** cmd_desc) : _total_time(0), _cmd_idx(cmd_idx), _col_count(col_count), _cmd_desc(cmd_desc) { - - //memset(_counters, 0, sizeof(_counters)); + memset(_counters, 0, sizeof(_counters)); } void add_and_reset(Command_Counter* cc) { for (int j = 0; j < static_cast(sizeof(_counters)/sizeof(_counters[0])); j++) { diff --git a/lib/PgSQL_Query_Processor.cpp b/lib/PgSQL_Query_Processor.cpp index f880db0be..8820d9a4f 100644 --- a/lib/PgSQL_Query_Processor.cpp +++ b/lib/PgSQL_Query_Processor.cpp @@ -245,7 +245,9 @@ PgSQL_Query_Processor::~PgSQL_Query_Processor() { void PgSQL_Query_Processor::update_query_processor_stats() { Query_Processor::update_query_processor_stats(); - for (int i = 0; i < PGSQL_QUERY___NONE; i++) commands_counters[i]->add_and_reset(_thr_commands_counters[i]); + for (int i = 0; i < PGSQL_QUERY___NONE; i++) { + commands_counters[i]->add_and_reset(_thr_commands_counters[i]); + } } void PgSQL_Query_Processor::init_thread() {