helper_thread: check for null scalloc return value
authorVincent Fu <vincent.fu@samsung.com>
Tue, 11 Jun 2024 20:19:38 +0000 (16:19 -0400)
committerVincent Fu <vincent.fu@samsung.com>
Tue, 11 Jun 2024 20:19:38 +0000 (16:19 -0400)
scalloc can return NULL if it fails to allocate memory. Check for this
condition and fail the helper thread setup if it occurs.

This issue was reported by Coverity:

** CID 496644:  Null pointer dereferences  (NULL_RETURNS)
/helper_thread.c: 425 in helper_thread_create()
419
420      hd = scalloc(1, sizeof(*hd));
421
422      setup_disk_util();
423      steadystate_setup();
424
>>>     CID 496644:  Null pointer dereferences  (NULL_RETURNS)
>>>     Dereferencing "hd", which is known to be "NULL".
425      hd->sk_out = sk_out;

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
helper_thread.c

index 332ccb53c254e45087919f9a1f758390a9873f2f..fed21d1d61e7b5dcca82a51f4c343e5eff868cb8 100644 (file)
@@ -418,6 +418,8 @@ int helper_thread_create(struct fio_sem *startup_sem, struct sk_out *sk_out)
        int ret;
 
        hd = scalloc(1, sizeof(*hd));
+       if (!hd)
+               return 1;
 
        setup_disk_util();
        steadystate_setup();