From dd3d43d89e398f23c4824d26f2698446ff2d120f Mon Sep 17 00:00:00 2001 From: Dotan Barak Date: Tue, 16 Jan 2007 12:21:25 -0800 Subject: [PATCH] Handle asprintf memory allocation failures Signed-off-by: Dotan Barak Signed-off-by: Roland Dreier --- src/device.c | 3 ++- src/sysfs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/device.c b/src/device.c index 3bfbca6..f7ef224 100644 --- a/src/device.c +++ b/src/device.c @@ -111,7 +111,8 @@ struct ibv_context *ibv_open_device(struct ibv_device *device) int cmd_fd; struct ibv_context *context; - asprintf(&devpath, "/dev/infiniband/%s", device->dev_name); + if (asprintf(&devpath, "/dev/infiniband/%s", device->dev_name)) + return NULL; /* * We'll only be doing writes, but we need O_RDWR in case the diff --git a/src/sysfs.c b/src/sysfs.c index e274c03..392a675 100644 --- a/src/sysfs.c +++ b/src/sysfs.c @@ -82,7 +82,8 @@ int ibv_read_sysfs_file(const char *dir, const char *file, int fd; int len; - asprintf(&path, "%s/%s", dir, file); + if (asprintf(&path, "%s/%s", dir, file)) + return -1; fd = open(path, O_RDONLY); if (fd < 0) { -- 2.46.0