PG_FREE_IF_COPY extraneous in numeric_cmp?

From: CK Tan <cktan(at)vitessedata(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: PG_FREE_IF_COPY extraneous in numeric_cmp?
Date: 2023-02-24 18:51:12
Message-ID: CAJNt7=Zr0Vz-OoB=TePYUKRDaDD6PA7BHjD3yze4psYU9j7mUg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

I have a question on the code below:

Datum
numeric_cmp(PG_FUNCTION_ARGS)
{
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
int result;

result = cmp_numerics(num1, num2);

PG_FREE_IF_COPY(num1, 0);
PG_FREE_IF_COPY(num2, 1);

PG_RETURN_INT32(result);
}

It seems to me that num1 is a copy of fcinfo->arg[0]. It is passed to
the function cmp_numerics(), It's value remains the same after the
call. Also, cmp_numerics() does not have a handle to fcinfo, so it
can't modify fcinfo->arg[0].

Isn't it true that pfree() will never be called by PG_FREE_IF_COPY?

Cheers,
-cktan

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2023-02-24 19:14:12 Re: PATCH: Using BRIN indexes for sorted output
Previous Message Nathan Bossart 2023-02-24 18:31:09 Re: Inconsistency in ACL error message