pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.42k stars 2.17k forks source link

Memory leak while executing SQL Statement #942

Closed krishnavivek closed 9 years ago

krishnavivek commented 9 years ago

We observe a memory leak while executing a PGSql statement from a session. Below is the stack trace captured using Valgrind.


218591 ==72266== by 0x9B16458: QR_Constructor (qresult.c:138) 218592 ==72266== by 0x9B2A8E1: SC_pre_execute (statement.c:1099) 218593 ==72266== by 0x9B21232: SC_pre_execute_ok (results.c:96) 218594 ==72266== by 0x9B22AA5: PGAPI_NumResultCols (results.c:193) 218595 ==72266== by 0x9B35600: SQLNumResultCols (odbcapi.c:618) 218596 ==72266== by 0x9078511: SQLNumResultCols (SQLNumResultCols.c:220) 218597 ==72266== by 0x37EC234: Poco::Data::ODBC::Preparation::Preparation(Poco::Data::ODBC::Handle<void*, (short)3> const&, std::string const&, unsigned long, Poco::Data: :ODBC::Preparation::DataExtraction) (in /var/mps64/main/ion_55_5_nmx/usr.src/sdx/mps/install/lib/libPocoDataODBC.so.16) 218598 ==72266== by 0x37E7263: Poco::Data::ODBC::ODBCStatementImpl::compileImpl() (in /var/mps64/main/ion_55_5_nmx/usr.src/sdx/mps/install/lib/libPocoDataODBC.so.16) 218599 ==72266== by 0x36A7527: Poco::Data::StatementImpl::compile() (in /var/mps64/main/ion_55_5_nmx/usr.src/sdx/mps/install/lib/libPocoData.so.16) 218600 ==72266== by 0x36A75B8: Poco::Data::StatementImpl::executeWithoutLimit() (in /var/mps64/main/ion_55_5_nmx/usr.src/sdx/mps/install/lib/libPocoData.so.16) 218601 ==72266== by 0x36A7907: Poco::Data::StatementImpl::execute() (in /var/mps64/main/ion_55_5_nmx/usr.src/sdx/mps/install/lib/libPocoData.so.16)


Below is the code of how it is being invoked.

connection = (POCOConnection*) DBConnectionPool::instance()->getDBConnection(POCO_CONNECTION);

if(rpt_obj.get_db_table_name() == "perf_vserver_service_thrpt_report")
{
    table_name = "perf_vserver_service_thrpt_report_l1";
    table_name_to_operate = "perf_vserver_service_thrpt_report";
    insert_qry = " INSERT INTO " + table_name +
            " ( device_ip_address, timestamp,TotalVServerBytes,TotalVServiceBytes,vserverName,vserviceName ) ";

    select_qry = " (select distinct(device_ip_address), "+ MPSUtil::long_string(start_time) + ", AVG(TotalVServerBytes) as TotalVServerBytes, "
            " AVG(TotalVServiceBytes)  as TotalVServiceBytes " +
            " from "+ table_name_to_operate +" WHERE ( "+  condition + ") "
            " GROUP BY device_ip_address ) ";

    full_qry_str = insert_qry + select_qry;

    MPSLogger::instance()->debug("The final full_qry_str: " + full_qry_str);
    try{

        *(connection->getSession()) <<full_qry_str, now;
    }
    catch(Exception& ex)
    {
        MPSLogger::instance()->error("DB Exception PerformAgg " + ex.displayText());
    }

Please acknowledge with your observations.

krishnavivek commented 9 years ago

The INSERT statements are causing the leak. I am not sure about the root cause.

aleks-f commented 9 years ago

See this issue. If you can figure out where the problem is, send us a fix.