From 57e49a03de9505a0e78b3c554786afa6d9d3b400 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 1 Oct 2004 14:01:19 +0000 Subject: Avoid overwriting the cursor page when the cursor page becomes the LRU page. From pacman at manson dot clss dot net. ok deraadt@ millert@ --- lib/libc/db/hash/hash_buf.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/libc/db/hash/hash_buf.c') diff --git a/lib/libc/db/hash/hash_buf.c b/lib/libc/db/hash/hash_buf.c index 224c1cace9f..c4a31d35c96 100644 --- a/lib/libc/db/hash/hash_buf.c +++ b/lib/libc/db/hash/hash_buf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hash_buf.c,v 1.12 2003/06/02 20:18:33 millert Exp $ */ +/* $OpenBSD: hash_buf.c,v 1.13 2004/10/01 14:01:18 otto Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -36,7 +36,7 @@ #if 0 static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94"; #else -static const char rcsid[] = "$OpenBSD: hash_buf.c,v 1.12 2003/06/02 20:18:33 millert Exp $"; +static const char rcsid[] = "$OpenBSD: hash_buf.c,v 1.13 2004/10/01 14:01:18 otto Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -174,11 +174,19 @@ newbuf(hashp, addr, prev_bp) oaddr = 0; bp = LRU; + + /* It is bad to overwrite the page under the cursor. */ + if (bp == hashp->cpage) { + BUF_REMOVE(bp); + MRU_INSERT(bp); + bp = LRU; + } + /* * If LRU buffer is pinned, the buffer pool is too small. We need to * allocate more buffers. */ - if (hashp->nbufs || (bp->flags & BUF_PIN)) { + if (hashp->nbufs || (bp->flags & BUF_PIN) || bp == hashp->cpage) { /* Allocate a new one */ if ((bp = (BUFHEAD *)malloc(sizeof(BUFHEAD))) == NULL) return (NULL); -- cgit v1.2.3