Re: \if, \elseif, \else, \endif (was Re: PSQL commands:\quit_if, \quit_unless) - Mailing list pgsql-hackers

From Fabien COELHO
Subject Re: \if, \elseif, \else, \endif (was Re: PSQL commands:\quit_if, \quit_unless)
Date
Msg-id alpine.DEB.2.20.1703270655240.20202@lancre
Whole thread Raw
In response to Re: [HACKERS] \if, \elseif, \else, \endif (was Re: PSQL commands:\quit_if, \quit_unless)  ("Daniel Verite" <daniel@manitou-mail.org>)
Responses Re: \if, \elseif, \else, \endif (was Re: PSQL commands:\quit_if, \quit_unless)  (Corey Huinker <corey.huinker@gmail.com>)
List pgsql-hackers

>> ISTM that PQExpBuffer is partially a memory leak. Something should need 
>> to be freed?
>
> I copied that pattern from somewhere else, so yeah, I duplicated whatever
> leak was there.

Hmmm. Indeed some commands do not free, but there is a single use and the 
commands exits afterwards, eg "createuser".

I think that you could use another pattern where you init the 
PQExpBufferData structure instead of create it, so that only the string is 
malloced.

>> I think that you should use appendPQExpBufferChar and Str instead of
>> relying on the format variant which is probably expensive. Something like:
>>
>>   if (num_options > 0)
>>     append...Char(buf, ' ');
>>   append...Str(buf, ...);
>
> All flavors of appendPQExpBuffer*() I can find have a const *char format 
> string, so no way to append a naked string. If you know differently, I'm 
> listening. Not fixed.

These prototypes are from "pqexpbuffer.h", and do not seem to rely on a 
format:
 extern void appendPQExpBufferChar(PQExpBuffer str, char ch); extern void appendPQExpBufferStr(PQExpBuffer str, const
char*data);
 

-- 
Fabien



pgsql-hackers by date:

Previous
From: Andreas Karlsson
Date:
Subject: Re: Refactor handling of database attributes betweenpg_dump and pg_dumpall
Next
From: Tom Lane
Date:
Subject: Re: crashes due to setting max_parallel_workers=0