From 85c1e895a5b4d520481de419aff04c2519198894 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 19 Apr 2012 10:27:07 +0200 Subject: s3: Fix Coverity ID 2745 and 2746: FORWARD_NULL We can assume that the rbt dbs are around --- source3/lib/dbwrap/dbwrap_cache.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'source3') diff --git a/source3/lib/dbwrap/dbwrap_cache.c b/source3/lib/dbwrap/dbwrap_cache.c index ded85258a3..e0fced591b 100644 --- a/source3/lib/dbwrap/dbwrap_cache.c +++ b/source3/lib/dbwrap/dbwrap_cache.c @@ -30,15 +30,17 @@ struct db_cache_ctx { struct db_context *negative; }; -static void dbwrap_cache_validate(struct db_cache_ctx *ctx) +static bool dbwrap_cache_validate(struct db_cache_ctx *ctx) { if (ctx->seqnum == dbwrap_get_seqnum(ctx->backing)) { - return; + return true; } TALLOC_FREE(ctx->positive); ctx->positive = db_open_rbt(ctx); TALLOC_FREE(ctx->negative); ctx->negative = db_open_rbt(ctx); + + return ((ctx->positive != NULL) && (ctx->negative != NULL)); } static NTSTATUS dbwrap_cache_parse_record( @@ -51,16 +53,15 @@ static NTSTATUS dbwrap_cache_parse_record( TDB_DATA value; NTSTATUS status; - dbwrap_cache_validate(ctx); + if (!dbwrap_cache_validate(ctx)) { + return NT_STATUS_NO_MEMORY; + } - if (ctx->positive != NULL) { - status = dbwrap_parse_record( - ctx->positive, key, parser, private_data); - if (NT_STATUS_IS_OK(status)) { - return status; - } + status = dbwrap_parse_record(ctx->positive, key, parser, private_data); + if (NT_STATUS_IS_OK(status)) { + return status; } - if ((ctx->negative != NULL) && dbwrap_exists(ctx->negative, key)) { + if (dbwrap_exists(ctx->negative, key)) { return NT_STATUS_NOT_FOUND; } @@ -191,7 +192,10 @@ struct db_context *db_open_cache(TALLOC_CTX *mem_ctx, ctx->seqnum = -1; ctx->backing = talloc_move(ctx, &backing); db->private_data = ctx; - dbwrap_cache_validate(ctx); + if (!dbwrap_cache_validate(ctx)) { + TALLOC_FREE(db); + return NULL; + } db->fetch_locked = dbwrap_cache_fetch_locked; db->try_fetch_locked = NULL; -- cgit