public inbox for [email protected]  
help / color / mirror / Atom feed
Re: How to properly fix memory leak
2+ messages / 2 participants
[nested] [flat]

* Re: How to properly fix memory leak
@ 2025-04-26 20:53 Igor Korot <[email protected]>
  2025-04-26 21:34 ` Re: How to properly fix memory leak Tom Lane <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Igor Korot @ 2025-04-26 20:53 UTC (permalink / raw)
  To: Laurenz Albe <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]>

Hi, Lauren’s,

On Sat, Apr 26, 2025 at 3:30 PM Laurenz Albe <[email protected]>
wrote:

> 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().


No, it is not spurious.
I’m getting it every time I run the program.

The m_tablespaces variable is declared as “std::vector<std::wstring>. No
pointer is involved.
I don’t see how it can produce the leak…

Thank you.


>
> Yours,
> Laurenz Albe
>


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: How to properly fix memory leak
  2025-04-26 20:53 Re: How to properly fix memory leak Igor Korot <[email protected]>
@ 2025-04-26 21:34 ` Tom Lane <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2025-04-26 21:34 UTC (permalink / raw)
  To: Igor Korot <[email protected]>; +Cc: Laurenz Albe <[email protected]>; pgsql-generallists.postgresql.org <[email protected]>

Igor Korot <[email protected]> writes:
>>>> auto temp1 = m_pimpl->m_myconv.from_bytes( PQgetvalue(
>>>>                                                       res, i, 1 ) );
>>>> m_tablespaces.push_back( temp1 );

I would imagine that from_bytes() is producing a malloc'd
string.  Which part of this is responsible for seeing that
that gets freed?

			regards, tom lane






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2025-04-26 21:34 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-04-26 20:53 Re: How to properly fix memory leak Igor Korot <[email protected]>
2025-04-26 21:34 ` Tom Lane <[email protected]>

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