Re: How to properly fix memory leak

From: Igor Korot <ikorot01(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "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 05:12:59
Message-ID: CA+FnnTx5QBqs2WFAu+Bznv2z73i+j8aZXGDMB0ocE=Wb6hy4eA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, David,

On Fri, Apr 25, 2025 at 11:55 PM David G. Johnston
<david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>
> On Friday, April 25, 2025, Igor Korot <ikorot01(at)gmail(dot)com> wrote:
>>
>>
>> And the error case was handled correctly, right?
>
>
> Seems like answering that requires knowing what the query is or can be. I also have no idea what idiomatic code looks like. Though, I’d probably use PQresultErrorMessage and check affirmatively for the tuples and error cases and have a final else should the status be something unexpected.

Understood.

Below is the full function:

[code]
int PostgresDatabase::PopulateTablespaces(std::vector<std::wstring> &errorMsg)
{
int result = 0;
std::wstring errorMessage;
std::wstring query = L"SELECT * FROM pg_tablespace;";
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 );
}
}
PQclear( res );
return result;
}
[/code]

Thank you.

>
> David J.
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2025-04-26 20:30:28 Re: How to properly fix memory leak
Previous Message David G. Johnston 2025-04-26 04:55:14 How to properly fix memory leak