diff options
author | pst <pst@FreeBSD.org> | 1996-02-27 19:42:00 +0000 |
---|---|---|
committer | pst <pst@FreeBSD.org> | 1996-02-27 19:42:00 +0000 |
commit | 912836fc11fb14d3f93b1bbd3d937daf0364a21f (patch) | |
tree | 282ca344758456835717d95b22f07b9d665d2134 /lib/libc/db/btree/bt_close.c | |
parent | 221f5fcda8cae5ef7821d99fddd45a0d52a012f2 (diff) | |
download | FreeBSD-src-912836fc11fb14d3f93b1bbd3d937daf0364a21f.zip FreeBSD-src-912836fc11fb14d3f93b1bbd3d937daf0364a21f.tar.gz |
Fix conflicts and merge into mainline
Diffstat (limited to 'lib/libc/db/btree/bt_close.c')
-rw-r--r-- | lib/libc/db/btree/bt_close.c | 82 |
1 files changed, 30 insertions, 52 deletions
diff --git a/lib/libc/db/btree/bt_close.c b/lib/libc/db/btree/bt_close.c index 6269bd5..27f9ab6 100644 --- a/lib/libc/db/btree/bt_close.c +++ b/lib/libc/db/btree/bt_close.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993 + * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_close.c 8.3 (Berkeley) 2/21/94"; +static char sccsid[] = "@(#)bt_close.c 8.7 (Berkeley) 8/17/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -75,25 +75,30 @@ __bt_close(dbp) t->bt_pinned = NULL; } - /* - * Delete any already deleted record that we've been saving - * because the cursor pointed to it. - */ - if (ISSET(t, B_DELCRSR) && __bt_crsrdel(t, &t->bt_bcursor)) - return (RET_ERROR); - + /* Sync the tree. */ if (__bt_sync(dbp, 0) == RET_ERROR) return (RET_ERROR); + /* Close the memory pool. */ if (mpool_close(t->bt_mp) == RET_ERROR) return (RET_ERROR); - if (t->bt_stack) - free(t->bt_stack); - if (t->bt_kbuf) - free(t->bt_kbuf); - if (t->bt_dbuf) - free(t->bt_dbuf); + /* Free random memory. */ + if (t->bt_cursor.key.data != NULL) { + free(t->bt_cursor.key.data); + t->bt_cursor.key.size = 0; + t->bt_cursor.key.data = NULL; + } + if (t->bt_rkey.data) { + free(t->bt_rkey.data); + t->bt_rkey.size = 0; + t->bt_rkey.data = NULL; + } + if (t->bt_rdata.data) { + free(t->bt_rdata.data); + t->bt_rdata.size = 0; + t->bt_rdata.data = NULL; + } fd = t->bt_fd; free(t); @@ -117,8 +122,6 @@ __bt_sync(dbp, flags) { BTREE *t; int status; - PAGE *h; - void *p; t = dbp->internal; @@ -134,40 +137,15 @@ __bt_sync(dbp, flags) return (RET_ERROR); } - if (ISSET(t, B_INMEM | B_RDONLY) || !ISSET(t, B_MODIFIED)) + if (F_ISSET(t, B_INMEM | B_RDONLY) || !F_ISSET(t, B_MODIFIED)) return (RET_SUCCESS); - if (ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR) + if (F_ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR) return (RET_ERROR); - /* - * Nastiness. If the cursor has been marked for deletion, but not - * actually deleted, we have to make a copy of the page, delete the - * key/data item, sync the file, and then restore the original page - * contents. - */ - if (ISSET(t, B_DELCRSR)) { - if ((p = (void *)malloc(t->bt_psize)) == NULL) - return (RET_ERROR); - if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) - return (RET_ERROR); - memmove(p, h, t->bt_psize); - if ((status = - __bt_dleaf(t, h, t->bt_bcursor.index)) == RET_ERROR) - goto ecrsr; - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - } - if ((status = mpool_sync(t->bt_mp)) == RET_SUCCESS) - CLR(t, B_MODIFIED); - -ecrsr: if (ISSET(t, B_DELCRSR)) { - if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) - return (RET_ERROR); - memmove(h, p, t->bt_psize); - free(p); - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - } + F_CLR(t, B_MODIFIED); + return (status); } @@ -191,12 +169,12 @@ bt_meta(t) return (RET_ERROR); /* Fill in metadata. */ - m.m_magic = BTREEMAGIC; - m.m_version = BTREEVERSION; - m.m_psize = t->bt_psize; - m.m_free = t->bt_free; - m.m_nrecs = t->bt_nrecs; - m.m_flags = t->bt_flags & SAVEMETA; + m.magic = BTREEMAGIC; + m.version = BTREEVERSION; + m.psize = t->bt_psize; + m.free = t->bt_free; + m.nrecs = t->bt_nrecs; + m.flags = F_ISSET(t, SAVEMETA); memmove(p, &m, sizeof(BTMETA)); mpool_put(t->bt_mp, p, MPOOL_DIRTY); |