Re: How to properly fix memory leak - Mailing list pgsql-general

From Igor Korot
Subject Re: How to properly fix memory leak
Date
Msg-id CA+FnnTwW6bsN3zJSHYbc7cGUi_4+PBOmHx+L5bbupwKkUio9tQ@mail.gmail.com
Whole thread Raw
In response to Re: How to properly fix memory leak  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses How to properly fix memory leak
List pgsql-general
Hi, David,

On Fri, Apr 25, 2025 at 10:48 PM David G. Johnston
<david.g.johnston@gmail.com> wrote:
>
> On Friday, April 25, 2025, Igor Korot <ikorot01@gmail.com> wrote:
>>
>>
>>         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.
>
>
> Seems like a false positive.

And the error case was handled correctly, right?

Thank you.

>
>>
>>
>> Should I call PQclear() on every iteration of the loop?
>
>
> Would make processing more than a single row impossible if you throw away the result after processing one row.
>
> David J.
>



pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: How to properly fix memory leak
Next
From: "David G. Johnston"
Date:
Subject: How to properly fix memory leak