diff options
author | Simo Sorce <idra@samba.org> | 2008-01-16 12:06:34 -0500 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2008-01-16 12:06:34 -0500 |
commit | 04b2a9e80a8c35e37faf2e0a8e54efb9a084f2e3 (patch) | |
tree | 9cb49347eab028a5f65a4f2aa4c61de42cff08fd /source3/lib/dbwrap_tdb.c | |
parent | 94fdd59f1c2a41b8e737aa8ca8939e9bf2b59a77 (diff) | |
parent | 8c41366a98ea96224adc2c108b940075431944fd (diff) | |
download | samba-04b2a9e80a8c35e37faf2e0a8e54efb9a084f2e3.tar.gz samba-04b2a9e80a8c35e37faf2e0a8e54efb9a084f2e3.tar.bz2 samba-04b2a9e80a8c35e37faf2e0a8e54efb9a084f2e3.zip |
Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into v3-2-simo
(This used to be commit 05c22a55a4c052c682a2f2afdb0696504195d18c)
Diffstat (limited to 'source3/lib/dbwrap_tdb.c')
-rw-r--r-- | source3/lib/dbwrap_tdb.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/source3/lib/dbwrap_tdb.c b/source3/lib/dbwrap_tdb.c index 710e45de6b..e87ceb428f 100644 --- a/source3/lib/dbwrap_tdb.c +++ b/source3/lib/dbwrap_tdb.c @@ -31,6 +31,11 @@ static int db_tdb_record_destr(struct db_record* data) struct db_tdb_ctx *ctx = talloc_get_type_abort(data->private_data, struct db_tdb_ctx); + /* This hex_encode() call allocates memory on data context. By way how current + __talloc_free() code works, it is OK to allocate in the destructor as + the children of data will be freed after call to the destructor and this + new 'child' will be caught and freed correctly. + */ DEBUG(10, (DEBUGLEVEL > 10 ? "Unlocking key %s\n" : "Unlocking key %.20s\n", hex_encode(data, (unsigned char *)data->key.dptr, @@ -88,8 +93,9 @@ static struct db_record *db_tdb_fetch_locked(struct db_context *db, struct tdb_fetch_locked_state state; int res; - if (DEBUGLEVEL >= 10) { - char *keystr = hex_encode(NULL, key.dptr, key.dsize); + /* Do not accidently allocate/deallocate w/o need when debug level is lower than needed */ + if(DEBUGLEVEL >= 10) { + char *keystr = hex_encode(NULL, (unsigned char*)key.dptr, key.dsize); DEBUG(10, (DEBUGLEVEL > 10 ? "Locking key %s\n" : "Locking key %.20s\n", keystr)); @@ -191,15 +197,9 @@ static NTSTATUS db_tdb_delete(struct db_record *rec) { struct db_tdb_ctx *ctx = talloc_get_type_abort(rec->private_data, struct db_tdb_ctx); - int res; - - res = tdb_delete(ctx->wtdb->tdb, rec->key); - if (res == 0) { - return NT_STATUS_OK; - } - - return map_nt_error_from_tdb(tdb_error(ctx->wtdb->tdb)); + return (tdb_delete(ctx->wtdb->tdb, rec->key) == 0) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; } struct db_tdb_traverse_ctx { @@ -318,6 +318,7 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx, result->traverse = db_tdb_traverse; result->traverse_read = db_tdb_traverse_read; result->get_seqnum = db_tdb_get_seqnum; + result->persistent = ((tdb_flags & TDB_CLEAR_IF_FIRST) == 0); return result; fail: |