如标题中所述,我正在用PostgreSQL的C语言编写UDF。我正在通过DirectFunctionCall1
,DirectFunctionCall2
来调用某些函数,...其中一些函数返回POD(例如interval_finite
,timestamp_in
),而其中一些返回指针(像interval_in
,int4_to_char
)。
问题1:在调用返回指针的函数之后,应该调用pfree
释放那些指针吗?
Q2:如果Q1的答案是肯定的,我应该在将指针传递给另一个DirectFunctionCall1
函数作为参数之后释放Q1中的那些指针吗?
Interval *real_interval = NULL;
real_interval = DatumGetIntervalP(DirectFunctionCall2(
timestamp_mi,
TimestampTzGetDatum(timestamp_floor_small_period),
TimestampTzGetDatum(timestamp_floor_big_period)));
// Q1: should I call pfree(real_interval)?
result = DatumGetInt32(
DirectFunctionCall1( // Q2: Should I free the returned pointer of DirectFunctionCall?
numeric_int4,
DirectFunctionCall2( // Q2: Should I free the returned pointer of DirectFunctionCall?
numeric_div,
NumericGetDatum(
DatumGetNumeric(
DirectFunctionCall1( // Q2: Should I free the returned pointer of DirectFunctionCall?
intervaltonum,
IntervalPGetDatum(real_interval)
)
)
),
NumericGetDatum(
DatumGetNumeric(
DirectFunctionCall1( // Q2: Should I free the returned pointer of DirectFunctionCall?
intervaltonum,
IntervalPGetDatum(&small_interval)
)
)
)
)
)
);