Skip to content

Commit 8fa5394

Browse files
committed
Releasing empty root page in _bt_endpoint () to avoid
buffer leak.
1 parent b516466 commit 8fa5394

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/backend/access/nbtree/nbtsearch.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.12 1996/12/15 09:05:10 bryanh Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.13 1997/01/05 10:56:36 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1080,6 +1080,7 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
10801080

10811081
rel = scan->relation;
10821082
current = &(scan->currentItemData);
1083+
so = (BTScanOpaque) scan->opaque;
10831084

10841085
buf = _bt_getroot(rel, BT_READ);
10851086
blkno = BufferGetBlockNumber(buf);
@@ -1153,6 +1154,9 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
11531154
if ( start != P_HIKEY ) /* non-rightmost page */
11541155
elog (WARN, "_bt_endpoint: non-rightmost page (%u) is empty", blkno);
11551156
/* It's left- & right- most page - root page, - and it's empty... */
1157+
_bt_relbuf(rel, buf, BT_READ);
1158+
ItemPointerSetInvalid(current);
1159+
so->btso_curbuf = InvalidBuffer;
11561160
return ((RetrieveIndexResult) NULL);
11571161
}
11581162
if ( start > maxoff ) /* start == 2 && maxoff == 1 */
@@ -1188,7 +1192,12 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
11881192
{
11891193
/* If it's leftmost page too - it's empty root page... */
11901194
if ( P_LEFTMOST(opaque) )
1195+
{
1196+
_bt_relbuf(rel, buf, BT_READ);
1197+
ItemPointerSetInvalid(current);
1198+
so->btso_curbuf = InvalidBuffer;
11911199
return ((RetrieveIndexResult) NULL);
1200+
}
11921201
/* Go back ! */
11931202
ItemPointerSet(current, blkno, FirstOffsetNumber);
11941203
if (!_bt_step(scan, &buf, BackwardScanDirection))
@@ -1214,7 +1223,6 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
12141223
res = FormRetrieveIndexResult(current, &(itup->t_tid));
12151224

12161225
/* remember which buffer we have pinned */
1217-
so = (BTScanOpaque) scan->opaque;
12181226
so->btso_curbuf = buf;
12191227
} else {
12201228
_bt_relbuf(rel, buf, BT_READ);

0 commit comments

Comments
 (0)