summaryrefslogtreecommitdiff
path: root/lib/ntdb/check.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-19 12:42:08 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-19 05:38:07 +0200
commitd938c0b591d9c4aff9c92ae5eedd26ed97455f42 (patch)
treee3744f9c660fbf23d759493e0391d577e528ffcd /lib/ntdb/check.c
parent6d5a3e1602a1db8ca8e778f5e4f40bb623dff1e7 (diff)
downloadsamba-d938c0b591d9c4aff9c92ae5eedd26ed97455f42.tar.gz
samba-d938c0b591d9c4aff9c92ae5eedd26ed97455f42.tar.bz2
samba-d938c0b591d9c4aff9c92ae5eedd26ed97455f42.zip
ntdb: allocator attribute.
This is designed to allow us to make ntdb_context (and NTDB_DATA returned from ntdb_fetch) a talloc pointer. But it can also be used for any other alternate allocator. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ntdb/check.c')
-rw-r--r--lib/ntdb/check.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/ntdb/check.c b/lib/ntdb/check.c
index cff6e0345e..723e7b11bf 100644
--- a/lib/ntdb/check.c
+++ b/lib/ntdb/check.c
@@ -20,9 +20,17 @@
#include <ccan/asearch/asearch.h>
/* We keep an ordered array of offsets. */
-static bool append(ntdb_off_t **arr, size_t *num, ntdb_off_t off)
+static bool append(struct ntdb_context *ntdb,
+ ntdb_off_t **arr, size_t *num, ntdb_off_t off)
{
- ntdb_off_t *new = realloc(*arr, (*num + 1) * sizeof(ntdb_off_t));
+ ntdb_off_t *new;
+
+ if (*num == 0) {
+ new = ntdb->alloc_fn(ntdb, sizeof(ntdb_off_t), ntdb->alloc_data);
+ } else {
+ new = ntdb->expand_fn(*arr, (*num + 1) * sizeof(ntdb_off_t),
+ ntdb->alloc_data);
+ }
if (!new)
return false;
new[(*num)++] = off;
@@ -708,7 +716,7 @@ static enum NTDB_ERROR check_linear(struct ntdb_context *ntdb,
}
/* This record should be in free lists. */
if (frec_ftable(&rec.f) != NTDB_FTABLE_NONE
- && !append(fr, num_free, off)) {
+ && !append(ntdb, fr, num_free, off)) {
return ntdb_logerr(ntdb, NTDB_ERR_OOM,
NTDB_LOG_ERROR,
"ntdb_check: tracking %zu'th"
@@ -722,7 +730,7 @@ static enum NTDB_ERROR check_linear(struct ntdb_context *ntdb,
uint64_t klen, dlen, extra;
/* This record is used! */
- if (!append(used, num_used, off)) {
+ if (!append(ntdb, used, num_used, off)) {
return ntdb_logerr(ntdb, NTDB_ERR_OOM,
NTDB_LOG_ERROR,
"ntdb_check: tracking %zu'th"
@@ -858,7 +866,7 @@ _PUBLIC_ enum NTDB_ERROR ntdb_check_(struct ntdb_context *ntdb,
out:
ntdb_allrecord_unlock(ntdb, F_RDLCK);
ntdb_unlock_expand(ntdb, F_RDLCK);
- free(fr);
- free(used);
+ ntdb->free_fn(fr, ntdb->alloc_data);
+ ntdb->free_fn(used, ntdb->alloc_data);
return ecode;
}