Hi, there's a small bug in inv_fetchup().
In the following do-while loop, res is freed at the very
end of the loop. However, after getting out of the loop,
it gets freed again. Not good. Possible fix would be
changing the pfree(res) in the loop to:

  if (tuple == (HeapTuple)NULL) pfree(res);

------------------- inv_api.c ----------------------
		do
		{
			res = index_getnext(obj_desc->iscan, ForwardScanDirection);

			if (res == (RetrieveIndexResult) NULL)
			{
				ItemPointerSetInvalid(&(obj_desc->htid));
				return (HeapTuple) NULL;
			}

			/*
			 * For time travel, we need to use the actual time qual here,
			 * rather that NowTimeQual.  We currently have no way to pass
			 * a time qual in.
			 *
			 * This is now valid for snapshot !!! And should be fixed in some
			 * way...	- vadim 07/28/98
			 *
			 */

			tuple = heap_fetch(obj_desc->heap_r, SnapshotNow,
							   &res->heap_iptr, buffer);
			pfree(res);
		} while (tuple == (HeapTuple) NULL);

		/* remember this tid -- we may need it for later reads/writes */
		ItemPointerCopy(&(res->heap_iptr), &(obj_desc->htid));
		pfree(res);
	}
------------------- inv_api.c -----------------
--
Tatsuo Ishii
t-ishii@sra.co.jp


Sat, 3 Oct 1998 23:30:45 +0900
t-ishii@sra.co.jp (Tatsuo Ishii)
too many pfree in large object
> Hi, there's a small bug in inv_fetchup().
> In the following do-while loop, res is freed at the very
> end of the loop. However, after getting out of the loop,
> it gets freed again. Not good. Possible fix would be
> changing the pfree(res) in the loop to:
> 
>   if (tuple == (HeapTuple)NULL) pfree(res);
> 
> ------------------- inv_api.c ----------------------
> 			tuple = heap_fetch(obj_desc->heap_r, SnapshotNow,
> 							   &res->heap_iptr, buffer);
> 			pfree(res);
> 		} while (tuple == (HeapTuple) NULL);
> 
> 		/* remember this tid -- we may need it for later reads/writes */
> 		ItemPointerCopy(&(res->heap_iptr), &(obj_desc->htid));
> 		pfree(res);
> 	}

Thanks.  Fixed.  I changed the line to read:

        ItemPointerCopy(&tuple->t_ctid, &obj_desc->htid);

This way, I am getting it from the heap, not from the index tuple, and
removed the duplicate pfree().

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026


Mon, 5 Oct 1998 23:58:05 -0400 (EDT)
Bruce Momjian <maillist@candle.pha.pa.us>
Re: [HACKERS] too many pfree in large object