Memory leak: candela QueryResultIterator class's arrow operator
The QueryResultIterator::operator->()
creates a new instance of the Row
class on the heap each time it is called, but never deletes those instances. It's a public member function and is also invoked by the QueryResultIterator
constructor to initialise the row_
member variable.
Immediate thought: This is a strange design. I propose that the row_
member variable is initialised by directly calling new Row(*this)
, and then the operator->
method simply returns this->row_
without recreating it.
P.S. This was uncovered by running the TwinMux SWATCH cell under valgrind earlier today; sample of resulting valgrind report ...
==4208== 72 bytes in 9 blocks are definitely lost in loss record 4,285 of 7,937
==4208== at 0x4C28203: operator new(unsigned long) (vg_replace_malloc.c:334)
==4208== by 0x361147DA: tscandela::QueryResultIterator::operator->() (QueryResultIterator.cc:136)
==4208== by 0x3610368B: tscandela::DatabaseConnection::getReferencedColumn(std::string const&, std::string const&) (DatabaseConnection.cc:237)
==4208== by 0x36102D05: tscandela::DatabaseConnection::getReferencedTable(std::string const&, std::string const&) (DatabaseConnection.cc:191)
==4208== by 0x32D0AD57: swatchcellframework::DbManager::getHwStub(std::string const&) (DbManager.cpp:77)
==4208== by 0x32CD5F95: swatchcellframework::CellContext::replaceSystemFromDb(std::string const&, std::string const&, swatchcellframework::ContextWriteGuard const&) (CellContext.cpp:251)
==4208== by 0x32D4C8B3: swatchcellframework::RunControl::execEngage() (RunControl.cpp:380)
==4208== by 0x32D676CC: tsframework::CellFSM::StateMethod<swatchcellframework::RunControl>::method() (CellFSM.h:189)
==4208== by 0x2FC1ACC9: tsframework::CellFSM::interStateMethod(toolbox::fsm::FiniteStateMachine&) (CellFSM.cc:94)
==4208== by 0x32D675C3: toolbox::fsm::FiniteStateMachine::StateChanged<tsframework::CellFSM>::invoke(toolbox::fsm::FiniteStateMachine&) (FiniteStateMachine.h:201)
==4208== by 0x5BC106D: toolbox::fsm::FiniteStateMachine::fireEvent(toolbox::mem::CountingPtr<toolbox::Event, toolbox::mem::ThreadSafeReferenceCount, toolbox::mem::StandardObjectPolicy>) (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x2FC19332: tsframework::CellFSM::executeTransition(std::string const&) (CellFSM.cc:298)
==4208== by 0x2FBD5038: tsframework::CellOpSendCommand::code() (CellOpSendCommand.cc:74)
==4208== by 0x2FBC3570: tsframework::CellCommand::commandCode() (CellCommand.cc:287)
==4208== by 0x2FBC550B: tsframework::CellCommand::job(toolbox::task::WorkLoop*) (CellCommand.cc:180)
==4208== by 0x5BB5276: toolbox::task::WaitingWorkLoop::process() (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x5BB0FA0: toolbox::task::WorkLoop::run() (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x5BB1416: toolbox::task::thread_func(void*) (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x50C2DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==4208== by 0x838773C: clone (in /usr/lib64/libc-2.17.so)
==4208==
==4208== 72 bytes in 9 blocks are definitely lost in loss record 4,286 of 7,937
==4208== at 0x4C28203: operator new(unsigned long) (vg_replace_malloc.c:334)
==4208== by 0x361147DA: tscandela::QueryResultIterator::operator->() (QueryResultIterator.cc:136)
==4208== by 0x36103DA8: tscandela::DatabaseConnection::getPK(std::string const&, std::string const&) (DatabaseConnection.cc:271)
==4208== by 0x3610E8BF: tscandela::Table::getPK() const (Table.cc:67)
==4208== by 0x3610F2D1: tscandela::Table::selectRowByPK(std::string const&) const (Table.cc:156)
==4208== by 0x32D0AD86: swatchcellframework::DbManager::getHwStub(std::string const&) (DbManager.cpp:78)
==4208== by 0x32CD5F95: swatchcellframework::CellContext::replaceSystemFromDb(std::string const&, std::string const&, swatchcellframework::ContextWriteGuard const&) (CellContext.cpp:251)
==4208== by 0x32D4C8B3: swatchcellframework::RunControl::execEngage() (RunControl.cpp:380)
==4208== by 0x32D676CC: tsframework::CellFSM::StateMethod<swatchcellframework::RunControl>::method() (CellFSM.h:189)
==4208== by 0x2FC1ACC9: tsframework::CellFSM::interStateMethod(toolbox::fsm::FiniteStateMachine&) (CellFSM.cc:94)
==4208== by 0x32D675C3: toolbox::fsm::FiniteStateMachine::StateChanged<tsframework::CellFSM>::invoke(toolbox::fsm::FiniteStateMachine&) (FiniteStateMachine.h:201)
==4208== by 0x5BC106D: toolbox::fsm::FiniteStateMachine::fireEvent(toolbox::mem::CountingPtr<toolbox::Event, toolbox::mem::ThreadSafeReferenceCount, toolbox::mem::StandardObjectPolicy>) (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x2FC19332: tsframework::CellFSM::executeTransition(std::string const&) (CellFSM.cc:298)
==4208== by 0x2FBD5038: tsframework::CellOpSendCommand::code() (CellOpSendCommand.cc:74)
==4208== by 0x2FBC3570: tsframework::CellCommand::commandCode() (CellCommand.cc:287)
==4208== by 0x2FBC550B: tsframework::CellCommand::job(toolbox::task::WorkLoop*) (CellCommand.cc:180)
==4208== by 0x5BB5276: toolbox::task::WaitingWorkLoop::process() (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x5BB0FA0: toolbox::task::WorkLoop::run() (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x5BB1416: toolbox::task::thread_func(void*) (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x50C2DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==4208== by 0x838773C: clone (in /usr/lib64/libc-2.17.so)
==4208==
==4208== 72 bytes in 9 blocks are definitely lost in loss record 4,287 of 7,937
==4208== at 0x4C28203: operator new(unsigned long) (vg_replace_malloc.c:334)
==4208== by 0x361147DA: tscandela::QueryResultIterator::operator->() (QueryResultIterator.cc:136)
==4208== by 0x32D0AFE5: swatchcellframework::DbManager::getHwStub(std::string const&) (DbManager.cpp:87)
==4208== by 0x32CD5F95: swatchcellframework::CellContext::replaceSystemFromDb(std::string const&, std::string const&, swatchcellframework::ContextWriteGuard const&) (CellContext.cpp:251)
==4208== by 0x32D4C8B3: swatchcellframework::RunControl::execEngage() (RunControl.cpp:380)
==4208== by 0x32D676CC: tsframework::CellFSM::StateMethod<swatchcellframework::RunControl>::method() (CellFSM.h:189)
==4208== by 0x2FC1ACC9: tsframework::CellFSM::interStateMethod(toolbox::fsm::FiniteStateMachine&) (CellFSM.cc:94)
==4208== by 0x32D675C3: toolbox::fsm::FiniteStateMachine::StateChanged<tsframework::CellFSM>::invoke(toolbox::fsm::FiniteStateMachine&) (FiniteStateMachine.h:201)
==4208== by 0x5BC106D: toolbox::fsm::FiniteStateMachine::fireEvent(toolbox::mem::CountingPtr<toolbox::Event, toolbox::mem::ThreadSafeReferenceCount, toolbox::mem::StandardObjectPolicy>) (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x2FC19332: tsframework::CellFSM::executeTransition(std::string const&) (CellFSM.cc:298)
==4208== by 0x2FBD5038: tsframework::CellOpSendCommand::code() (CellOpSendCommand.cc:74)
==4208== by 0x2FBC3570: tsframework::CellCommand::commandCode() (CellCommand.cc:287)
==4208== by 0x2FBC550B: tsframework::CellCommand::job(toolbox::task::WorkLoop*) (CellCommand.cc:180)
==4208== by 0x5BB5276: toolbox::task::WaitingWorkLoop::process() (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x5BB0FA0: toolbox::task::WorkLoop::run() (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x5BB1416: toolbox::task::thread_func(void*) (in /opt/xdaq/lib/libtoolbox.so)
==4208== by 0x50C2DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==4208== by 0x838773C: clone (in /usr/lib64/libc-2.17.so)