Re: free C string

Поиск
Список
Период
Сортировка
Искать

Re: free C string

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Zhihong Yu  writes:
> I was looking at fmgr_internal_validator().
> It seems prosrc is only used internally.
> The patch frees the C string prosrc points to, prior to returning.

There's really very little point in adding such code.  Our memory
context mechanisms take care of minor leaks like this, with less
code and fewer cycles expended than explicit pfree calls require.
It's worth trying to clean up explicitly in code that might get
executed many times in a row, or might be allocating very big
temporary chunks; but fmgr_internal_validator hardly falls in
that category.

			regards, tom lane


free C string

От:
Zhihong Yu <zyu@yugabyte.com>
Дата:
Вложения:
Hi,
I was looking at fmgr_internal_validator().

It seems prosrc is only used internally.

The patch frees the C string prosrc points to, prior to returning.

Please take a look.

Thanks

Re: free C string

От:
Zhihong Yu <zyu@yugabyte.com>
Дата:
Вложения:


On Wed, Jul 14, 2021 at 10:17 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Zhihong Yu <zyu@yugabyte.com> writes:
> I was looking at fmgr_internal_validator().
> It seems prosrc is only used internally.
> The patch frees the C string prosrc points to, prior to returning.

There's really very little point in adding such code.  Our memory
context mechanisms take care of minor leaks like this, with less
code and fewer cycles expended than explicit pfree calls require.
It's worth trying to clean up explicitly in code that might get
executed many times in a row, or might be allocating very big
temporary chunks; but fmgr_internal_validator hardly falls in
that category.

                        regards, tom lane
Hi,
How about this occurrence which is in a loop ?

Thanks 

Re: free C string

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Zhihong Yu  writes:
> On Wed, Jul 14, 2021 at 10:17 AM Tom Lane  wrote:
>> There's really very little point in adding such code.  Our memory
>> context mechanisms take care of minor leaks like this, with less
>> code and fewer cycles expended than explicit pfree calls require.
>> It's worth trying to clean up explicitly in code that might get
>> executed many times in a row, or might be allocating very big
>> temporary chunks; but fmgr_internal_validator hardly falls in
>> that category.

> How about this occurrence which is in a loop ?

I'd say the burden is on you to prove that it's worth worrying
about, not vice versa.  If we added pfree everywhere we possibly
could, the code would be larger and slower, not faster.

			regards, tom lane


FAQ