Fix: object-pool.c: dereferenced before null check
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Mon, 16 Sep 2019 16:03:46 +0000 (12:03 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 19 Sep 2019 18:41:05 +0000 (14:41 -0400)
Coverity reported the following:
  CID 1401187 (#1 of 1): Dereference before null check
  (REVERSE_INULL)check_after_deref: Null-checking pool suggests that it
  may be null, but it has already been dereferenced on all paths leading
  to the check.

Add a `BT_ASSERT()` to ensure that `pool` is not null.

Reported-by: Coverity - 1401187 Dereference before null check (REVERSE_INULL)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ie18fecdad17c1a42db914d2eb987f783a4523871
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2054
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
src/lib/object-pool.c

index 8d95a890bbda66dd7da0ab497be3cc7a527f2e00..b31807434236acc32ccdb4f6733f2aa98c507592 100644 (file)
@@ -35,6 +35,7 @@ int bt_object_pool_initialize(struct bt_object_pool *pool,
 {
        int ret = 0;
 
+       BT_ASSERT(pool);
        BT_ASSERT(new_object_func);
        BT_ASSERT(destroy_object_func);
        BT_LOGD("Initializing object pool: addr=%p, data-addr=%p",
@@ -53,10 +54,7 @@ int bt_object_pool_initialize(struct bt_object_pool *pool,
        goto end;
 
 error:
-       if (pool) {
-               bt_object_pool_finalize(pool);
-       }
-
+       bt_object_pool_finalize(pool);
        ret = -1;
 
 end:
This page took 0.025068 seconds and 4 git commands to generate.