From 8fa5394c491cd3f4d934d7101b9b919aba6aa357 Mon Sep 17 00:00:00 2001 From: "Vadim B. Mikheev" Date: Sun, 5 Jan 1997 10:56:36 +0000 Subject: [PATCH] Releasing empty root page in _bt_endpoint () to avoid buffer leak. --- src/backend/access/nbtree/nbtsearch.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c index 9c07114bc4..569a9e7e7f 100644 --- a/src/backend/access/nbtree/nbtsearch.c +++ b/src/backend/access/nbtree/nbtsearch.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.12 1996/12/15 09:05:10 bryanh Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.13 1997/01/05 10:56:36 vadim Exp $ * *------------------------------------------------------------------------- */ @@ -1080,6 +1080,7 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) rel = scan->relation; current = &(scan->currentItemData); + so = (BTScanOpaque) scan->opaque; buf = _bt_getroot(rel, BT_READ); blkno = BufferGetBlockNumber(buf); @@ -1153,6 +1154,9 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) if ( start != P_HIKEY ) /* non-rightmost page */ elog (WARN, "_bt_endpoint: non-rightmost page (%u) is empty", blkno); /* It's left- & right- most page - root page, - and it's empty... */ + _bt_relbuf(rel, buf, BT_READ); + ItemPointerSetInvalid(current); + so->btso_curbuf = InvalidBuffer; return ((RetrieveIndexResult) NULL); } if ( start > maxoff ) /* start == 2 && maxoff == 1 */ @@ -1188,7 +1192,12 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) { /* If it's leftmost page too - it's empty root page... */ if ( P_LEFTMOST(opaque) ) + { + _bt_relbuf(rel, buf, BT_READ); + ItemPointerSetInvalid(current); + so->btso_curbuf = InvalidBuffer; return ((RetrieveIndexResult) NULL); + } /* Go back ! */ ItemPointerSet(current, blkno, FirstOffsetNumber); if (!_bt_step(scan, &buf, BackwardScanDirection)) @@ -1214,7 +1223,6 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) res = FormRetrieveIndexResult(current, &(itup->t_tid)); /* remember which buffer we have pinned */ - so = (BTScanOpaque) scan->opaque; so->btso_curbuf = buf; } else { _bt_relbuf(rel, buf, BT_READ); -- 2.40.0