summaryrefslogtreecommitdiff
path: root/usr.sbin/ldapd
diff options
context:
space:
mode:
authorMartin Hedenfal <martinh@cvs.openbsd.org>2010-06-13 06:49:52 +0000
committerMartin Hedenfal <martinh@cvs.openbsd.org>2010-06-13 06:49:52 +0000
commitc28274dcbc845f78f16c3941169314504517ed88 (patch)
treeb5c93ab1e963c417ecdf5b8fd5f3bd7c3f371265 /usr.sbin/ldapd
parent291eb4ca717b185b2570aeef1ebc6e3e06bcf7d3 (diff)
Fix btree reference counting when opening the database with a file
descriptor directly using btree_open_fd(). Also wrap referencing in a function.
Diffstat (limited to 'usr.sbin/ldapd')
-rw-r--r--usr.sbin/ldapd/btree.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/usr.sbin/ldapd/btree.c b/usr.sbin/ldapd/btree.c
index c263245e2da..2bb488a6e70 100644
--- a/usr.sbin/ldapd/btree.c
+++ b/usr.sbin/ldapd/btree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: btree.c,v 1.8 2010/06/11 08:40:32 martinh Exp $ */
+/* $OpenBSD: btree.c,v 1.9 2010/06/13 06:49:51 martinh Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -236,6 +236,7 @@ static int btree_is_meta_page(struct page *p);
static int btree_read_meta(struct btree *bt, pgno_t *p_next);
static int btree_write_meta(struct btree *bt, pgno_t root,
unsigned int flags);
+static void btree_ref(struct btree *bt);
static struct node *btree_search_node(struct btree *bt, struct mpage *mp,
struct btval *key, int *exactp, unsigned int *kip);
@@ -642,7 +643,7 @@ btree_txn_begin(struct btree *bt, int rdonly)
}
txn->bt = bt;
- bt->ref++;
+ btree_ref(bt);
if ((rc = btree_read_meta(bt, &txn->next_pgno)) == BT_FAIL ||
rc == BT_DEAD) {
@@ -970,6 +971,7 @@ btree_open_fd(int fd, uint32_t flags)
bt->fd = fd;
bt->flags = flags;
bt->flags &= ~BT_FIXPADDING;
+ bt->ref = 1;
if ((bt->page_cache = calloc(1, sizeof(*bt->page_cache))) == NULL)
goto fail;
@@ -1036,13 +1038,19 @@ btree_open(const char *path, uint32_t flags, mode_t mode)
close(fd);
else {
bt->path = strdup(path);
- bt->ref = 1;
DPRINTF("opened btree %p", bt);
}
return bt;
}
+static void
+btree_ref(struct btree *bt)
+{
+ bt->ref++;
+ DPRINTF("ref is now %d on btree %p", bt->ref, bt);
+}
+
void
btree_close(struct btree *bt)
{
@@ -1056,7 +1064,7 @@ btree_close(struct btree *bt)
free(bt->page_cache);
free(bt);
} else
- DPRINTF("ref is now %d", bt->ref);
+ DPRINTF("ref is now %d on btree %p", bt->ref, bt);
}
/* Search for key within a leaf page, using binary search.
@@ -1930,7 +1938,7 @@ btree_txn_cursor_open(struct btree *bt, struct btree_txn *txn)
SLIST_INIT(&cursor->stack);
cursor->bt = bt;
cursor->txn = txn;
- bt->ref++;
+ btree_ref(bt);
}
return cursor;