public inbox for [email protected]  
help / color / mirror / Atom feed
From: Laurenz Albe <[email protected]>
To: Igor Korot <[email protected]>
To: pgsql-generallists.postgresql.org <[email protected]>
Subject: Re: How to properly fix memory leak
Date: Sat, 26 Apr 2025 22:30:28 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CA+FnnTyR9AoJx-3zuvgudeYmUTiNcfpAucUh0ZTcs=Ajy49qVA@mail.gmail.com>
References: <CA+FnnTyR9AoJx-3zuvgudeYmUTiNcfpAucUh0ZTcs=Ajy49qVA@mail.gmail.com>

On Fri, 2025-04-25 at 22:24 -0500, Igor Korot wrote:
> 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...

No, PQclear() would cause an error (double free).

If it is not a spurious complaint, the leak would have to be in m_tablespaces.push_back().

Yours,
Laurenz Albe






reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: How to properly fix memory leak
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox