{
FmgrInfo *procedure;
int64 ntids;
+ Datum d;
SCAN_CHECKS;
GET_SCAN_PROCEDURE(amgetbitmap);
/*
* have the am's getbitmap proc do all the work.
*/
- ntids = DatumGetInt64(FunctionCall2(procedure,
- PointerGetDatum(scan),
- PointerGetDatum(bitmap)));
+ d = FunctionCall2(procedure,
+ PointerGetDatum(scan),
+ PointerGetDatum(bitmap));
+
+ ntids = DatumGetInt64(d);
+
+ /* If int8 is pass-by-ref, must free the result to avoid memory leak */
+#ifndef USE_FLOAT8_BYVAL
+ pfree(DatumGetPointer(d));
+#endif
pgstat_count_index_tuples(scan->indexRelation, ntids);