]> git.openfabrics.org - ~shefty/libibcm.git/commitdiff
Added checks to memory allocation failure when using asprintf
authorDotan Barak <dotanb@dev.mellanox.co.il>
Tue, 16 Jan 2007 09:51:33 +0000 (11:51 +0200)
committerSean Hefty <sean.hefty@intel.com>
Thu, 18 Jan 2007 04:18:17 +0000 (20:18 -0800)
Added checks to memory allocation failure when using asprintf.

Signed-off-by: Dotan Barak <dotanb@mellanox.co.il>
src/cm.c

index 85403b49a2de092f47e060e1946a2f48476ea535..25729726a6eb9056a77dcec4b8c6a0bce516a6fa 100644 (file)
--- a/src/cm.c
+++ b/src/cm.c
@@ -150,8 +150,9 @@ struct ib_cm_device* ib_cm_open_device(struct ibv_context *device_context)
 
        dev->device_context = device_context;
 
-       asprintf(&dev_path, "/dev/infiniband/ucm%s",
-                device_context->device->dev_name + sizeof("uverbs") - 1);
+       if (asprintf(&dev_path, "/dev/infiniband/ucm%s",
+                device_context->device->dev_name + sizeof("uverbs") - 1) < 0)
+               goto err2;
 
        dev->fd = open(dev_path, O_RDWR);
        if (dev->fd < 0) {
@@ -164,6 +165,7 @@ struct ib_cm_device* ib_cm_open_device(struct ibv_context *device_context)
 
 err:
        free(dev_path);
+err2:
        free(dev);
        return NULL;
 }