]> git.openfabrics.org - ~shefty/libibverbs.git/commitdiff
Check return of calloc() in ibv_get_device_list()
authorRoland Dreier <rolandd@cisco.com>
Wed, 17 Jan 2007 21:41:33 +0000 (13:41 -0800)
committerRoland Dreier <rolandd@cisco.com>
Wed, 17 Jan 2007 21:43:53 +0000 (13:43 -0800)
Don't blindly copy device pointers if calloc() returns NULL.

Signed-off-by: Roland Dreier <rolandd@cisco.com>
src/device.c

index f7ef224f4d916b183f2dbe1c4965e92b08484283..7f86e1a19193d4ffad39dd4415a617ae810aa846 100644 (file)
@@ -63,9 +63,13 @@ struct ibv_device **ibv_get_device_list(int *num)
                num_devices = ibverbs_init(&device_list);
 
        l = calloc(num_devices + 1, sizeof (struct ibv_device *));
+       if (!l)
+               goto out;
+
        for (i = 0; i < num_devices; ++i)
                l[i] = device_list[i];
 
+out:
        pthread_mutex_unlock(&device_list_lock);
 
        if (num)