From bb9b9d15e331e70b1dee95a841d786916985af82 Mon Sep 17 00:00:00 2001 From: Dotan Barak Date: Tue, 16 Jan 2007 11:51:33 +0200 Subject: [PATCH] Added checks to memory allocation failure when using asprintf Added checks to memory allocation failure when using asprintf. Signed-off-by: Dotan Barak --- src/cm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cm.c b/src/cm.c index 85403b4..2572972 100644 --- 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; } -- 2.41.0