diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-06-19 12:42:08 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-06-19 05:38:07 +0200 |
commit | d938c0b591d9c4aff9c92ae5eedd26ed97455f42 (patch) | |
tree | e3744f9c660fbf23d759493e0391d577e528ffcd /lib/ntdb/ntdb.c | |
parent | 6d5a3e1602a1db8ca8e778f5e4f40bb623dff1e7 (diff) | |
download | samba-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/ntdb.c')
-rw-r--r-- | lib/ntdb/ntdb.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/ntdb/ntdb.c b/lib/ntdb/ntdb.c index df9fe709b2..a74e0f4b78 100644 --- a/lib/ntdb/ntdb.c +++ b/lib/ntdb/ntdb.c @@ -204,7 +204,8 @@ _PUBLIC_ enum NTDB_ERROR ntdb_append(struct ntdb_context *ntdb, } /* Slow path. */ - newdata = malloc(key.dsize + old_dlen + dbuf.dsize); + newdata = ntdb->alloc_fn(ntdb, key.dsize + old_dlen + dbuf.dsize, + ntdb->alloc_data); if (!newdata) { ecode = ntdb_logerr(ntdb, NTDB_ERR_OOM, NTDB_LOG_ERROR, "ntdb_append:" @@ -230,7 +231,7 @@ _PUBLIC_ enum NTDB_ERROR ntdb_append(struct ntdb_context *ntdb, ecode = replace_data(ntdb, &h, key, new_dbuf, off, old_room, true); out_free_newdata: - free(newdata); + ntdb->free_fn(newdata, ntdb->alloc_data); out: ntdb_unlock_hashes(ntdb, h.hlock_start, h.hlock_range, F_WRLCK); return ecode; @@ -454,16 +455,20 @@ enum NTDB_ERROR COLD ntdb_logerr(struct ntdb_context *ntdb, return ecode; va_start(ap, fmt); - len = vasprintf(&message, fmt, ap); + len = vsnprintf(NULL, 0, fmt, ap); va_end(ap); - if (len < 0) { + message = ntdb->alloc_fn(ntdb, len + 1, ntdb->alloc_data); + if (!message) { ntdb->log_fn(ntdb, NTDB_LOG_ERROR, NTDB_ERR_OOM, "out of memory formatting message:", ntdb->log_data); ntdb->log_fn(ntdb, level, ecode, fmt, ntdb->log_data); } else { + va_start(ap, fmt); + vsnprintf(message, len+1, fmt, ap); + va_end(ap); ntdb->log_fn(ntdb, level, ecode, message, ntdb->log_data); - free(message); + ntdb->free_fn(message, ntdb->alloc_data); } errno = saved_errno; return ecode; |