Fix small query-lifespan memory leak introduced by 8.4 change in index AM API
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 10 Oct 2008 14:17:08 +0000 (14:17 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 10 Oct 2008 14:17:08 +0000 (14:17 +0000)
for bitmap index scans.  Per report and test case from Kevin Grittner.

src/backend/access/index/indexam.c

index 0d101acbe9ddf5da683e01e3d14ce1cfb4c8ac94..0a17f96b32f433f51ca60dadfe6eecea70857b86 100644 (file)
@@ -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);