diff options
author | 2006-01-25 14:40:03 +0000 | |
---|---|---|
committer | 2006-01-25 14:40:03 +0000 | |
commit | e2363574d2388970e48c4cb51e600e40f298c23b (patch) | |
tree | aed8cf0664bf068c44e0a5fb57365f0b1e4a75b3 /lib/libc/db/mpool/mpool.c | |
parent | this snprintf() occurence should have been removed in previous commit. (diff) | |
download | wireguard-openbsd-e2363574d2388970e48c4cb51e600e40f298c23b.tar.xz wireguard-openbsd-e2363574d2388970e48c4cb51e600e40f298c23b.zip |
Fix a memory leak that could be trigged by a read error
Update the count of currently cached pages in mpool_delete()
Use CIRCLEQ_EMPTY in the loop that delets the lru cache
Don't update the pageread statistic if there was a read error
With aaron@, OK krw@
Diffstat (limited to 'lib/libc/db/mpool/mpool.c')
-rw-r--r-- | lib/libc/db/mpool/mpool.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/libc/db/mpool/mpool.c b/lib/libc/db/mpool/mpool.c index 135fd73d4e1..65008de3d2d 100644 --- a/lib/libc/db/mpool/mpool.c +++ b/lib/libc/db/mpool/mpool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpool.c,v 1.17 2006/01/24 16:10:15 aaron Exp $ */ +/* $OpenBSD: mpool.c,v 1.18 2006/01/25 14:40:03 millert Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -159,6 +159,7 @@ mpool_delete(MPOOL *mp, void *page) CIRCLEQ_REMOVE(&mp->lqh, bp, q); free(bp); + mp->curcache--; return (RET_SUCCESS); } @@ -209,14 +210,13 @@ mpool_get(MPOOL *mp, pgno_t pgno, return (NULL); /* Read in the contents. */ -#ifdef STATISTICS - ++mp->pageread; -#endif off = mp->pagesize * pgno; if ((nr = pread(mp->fd, bp->page, mp->pagesize, off)) != mp->pagesize) { switch (nr) { case -1: /* errno is set for us by pread(). */ + free(bp); + mp->curcache--; return (NULL); case 0: /* @@ -227,10 +227,15 @@ mpool_get(MPOOL *mp, pgno_t pgno, break; default: /* A partial read is definitely bad. */ + free(bp); + mp->curcache--; errno = EINVAL; return (NULL); } } +#ifdef STATISTICS + ++mp->pageread; +#endif /* Set the page number, pin the page. */ bp->pgno = pgno; @@ -290,7 +295,8 @@ mpool_close(MPOOL *mp) BKT *bp; /* Free up any space allocated to the lru pages. */ - while ((bp = CIRCLEQ_FIRST(&mp->lqh)) != CIRCLEQ_END(&mp->lqh)) { + while (!CIRCLEQ_EMPTY(&mp->lqh)) { + bp = CIRCLEQ_FIRST(&mp->lqh); CIRCLEQ_REMOVE(&mp->lqh, bp, q); free(bp); } |