Commit 8fa5394c authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

Releasing empty root page in _bt_endpoint () to avoid

buffer leak.
parent b5164666
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -1080,6 +1080,7 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
rel = scan->relation; rel = scan->relation;
current = &(scan->currentItemData); current = &(scan->currentItemData);
so = (BTScanOpaque) scan->opaque;
buf = _bt_getroot(rel, BT_READ); buf = _bt_getroot(rel, BT_READ);
blkno = BufferGetBlockNumber(buf); blkno = BufferGetBlockNumber(buf);
...@@ -1153,6 +1154,9 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) ...@@ -1153,6 +1154,9 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
if ( start != P_HIKEY ) /* non-rightmost page */ if ( start != P_HIKEY ) /* non-rightmost page */
elog (WARN, "_bt_endpoint: non-rightmost page (%u) is empty", blkno); elog (WARN, "_bt_endpoint: non-rightmost page (%u) is empty", blkno);
/* It's left- & right- most page - root page, - and it's empty... */ /* 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); return ((RetrieveIndexResult) NULL);
} }
if ( start > maxoff ) /* start == 2 && maxoff == 1 */ if ( start > maxoff ) /* start == 2 && maxoff == 1 */
...@@ -1188,7 +1192,12 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) ...@@ -1188,7 +1192,12 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
{ {
/* If it's leftmost page too - it's empty root page... */ /* If it's leftmost page too - it's empty root page... */
if ( P_LEFTMOST(opaque) ) if ( P_LEFTMOST(opaque) )
{
_bt_relbuf(rel, buf, BT_READ);
ItemPointerSetInvalid(current);
so->btso_curbuf = InvalidBuffer;
return ((RetrieveIndexResult) NULL); return ((RetrieveIndexResult) NULL);
}
/* Go back ! */ /* Go back ! */
ItemPointerSet(current, blkno, FirstOffsetNumber); ItemPointerSet(current, blkno, FirstOffsetNumber);
if (!_bt_step(scan, &buf, BackwardScanDirection)) if (!_bt_step(scan, &buf, BackwardScanDirection))
...@@ -1214,7 +1223,6 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir) ...@@ -1214,7 +1223,6 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
res = FormRetrieveIndexResult(current, &(itup->t_tid)); res = FormRetrieveIndexResult(current, &(itup->t_tid));
/* remember which buffer we have pinned */ /* remember which buffer we have pinned */
so = (BTScanOpaque) scan->opaque;
so->btso_curbuf = buf; so->btso_curbuf = buf;
} else { } else {
_bt_relbuf(rel, buf, BT_READ); _bt_relbuf(rel, buf, BT_READ);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment