88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.110 2008/09/11 14:01:09 alvherre Exp $
11+ * $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.111 2008/10/10 14:17:08 tgl Exp $
1212 *
1313 * INTERFACE ROUTINES
1414 *index_open- open an index relation by relation OID
@@ -655,6 +655,7 @@ index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap)
655655{
656656FmgrInfo * procedure ;
657657int64 ntids ;
658+ Datum d ;
658659
659660SCAN_CHECKS ;
660661GET_SCAN_PROCEDURE (amgetbitmap );
@@ -665,9 +666,16 @@ index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap)
665666/*
666667 * have the am's getbitmap proc do all the work.
667668 */
668- ntids = DatumGetInt64 (FunctionCall2 (procedure ,
669- PointerGetDatum (scan ),
670- PointerGetDatum (bitmap )));
669+ d = FunctionCall2 (procedure ,
670+ PointerGetDatum (scan ),
671+ PointerGetDatum (bitmap ));
672+
673+ ntids = DatumGetInt64 (d );
674+
675+ /* If int8 is pass-by-ref, must free the result to avoid memory leak */
676+ #ifndef USE_FLOAT8_BYVAL
677+ pfree (DatumGetPointer (d ));
678+ #endif
671679
672680pgstat_count_index_tuples (scan -> indexRelation ,ntids );
673681