]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: Fix Coverity ID 2745 and 2746: FORWARD_NULL
authorVolker Lendecke <vl@samba.org>
Thu, 19 Apr 2012 08:27:07 +0000 (10:27 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 19 Apr 2012 15:37:37 +0000 (17:37 +0200)
We can assume that the rbt dbs are around

source3/lib/dbwrap/dbwrap_cache.c

index ded85258a3d4694e4efe308fc33cfb89f75f6f85..e0fced591b146526e31fcb266dae662e049aee63 100644 (file)
@@ -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;