Search Postgresql Archives

How to properly fix memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, ALL,

[code]
    auto res = PQexec( m_db, m_pimpl->m_myconv.to_bytes( query.c_str()
).c_str() );      /* ask for binary results */
    if( PQresultStatus( res ) != PGRES_TUPLES_OK )
    {
        auto err = m_pimpl->m_myconv.from_bytes( PQerrorMessage( m_db ) );
        errorMsg.push_back( L"Update validation table: " + err );
        result = 1;
    }
    else
    {
        for( int i = 0; i < PQntuples( res ); i++ )
        {
            auto temp1 = m_pimpl->m_myconv.from_bytes( PQgetvalue(
res, i, 1 ) );
            m_tablespaces.push_back( temp1 );
        } // this line gives a leak according to VLD
    }
    PQclear( res );
    return result;
[/code]

I ran this code on MSVC 2017  with VLD and according to the VLD report I have
a memory leak on the line indicated.

Should I call PQclear() on every iteration of the loop?

And I hope I handle the error cae properly...

Thank you





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux