aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/index/indexam.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-10-10 14:17:08 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-10-10 14:17:08 +0000
commit30584cda35543f58b9fd9911272d5c9583840a6f (patch)
treebab2f0d9c67bf77f51415b44214f9182600745cb /src/backend/access/index/indexam.c
parent8fc4197f7d015ab87ffccdb40d7b4d35fe92097a (diff)
downloadpostgresql-30584cda35543f58b9fd9911272d5c9583840a6f.tar.gz
postgresql-30584cda35543f58b9fd9911272d5c9583840a6f.zip
Fix small query-lifespan memory leak introduced by 8.4 change in index AM API
for bitmap index scans. Per report and test case from Kevin Grittner.
Diffstat (limited to 'src/backend/access/index/indexam.c')
-rw-r--r--src/backend/access/index/indexam.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 0c132d5fc09..76441be73d6 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.110 2008/09/11 14:01:09 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.111 2008/10/10 14:17:08 tgl Exp $
*
* INTERFACE ROUTINES
* index_open - open an index relation by relation OID
@@ -655,6 +655,7 @@ index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap)
{
FmgrInfo *procedure;
int64 ntids;
+ Datum d;
SCAN_CHECKS;
GET_SCAN_PROCEDURE(amgetbitmap);
@@ -665,9 +666,16 @@ index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap)
/*
* 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);