From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
---|---|
To: | Igor Korot <ikorot01(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: How to properly fix memory leak |
Date: | 2025-04-26 20:30:28 |
Message-ID: | 0a2be546e57d6088acf734f8d6a308a984e7171b.camel@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Igor Korot | 2025-04-26 20:53:58 | Re: How to properly fix memory leak |
Previous Message | Igor Korot | 2025-04-26 05:12:59 | Re: How to properly fix memory leak |