aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDotan Barak <dotanb@mellanox.co.il>2007-01-16 12:21:25 -0800
committerRoland Dreier <rolandd@cisco.com>2007-01-16 12:23:38 -0800
commit14b5ee0a4ecdb63222554d3bd31174d0ddbd2c0d (patch)
tree4426f26093780eeb646bdd05548970e253632dbd
parentd7f87055b443a22633e04d2c031940e353f41dfd (diff)
downloadlibibverbs-14b5ee0a4ecdb63222554d3bd31174d0ddbd2c0d.tar.gz
Handle asprintf memory allocation failures
Cherry-picked from dd3d43d89e398f23c4824d26f2698446ff2d120f. Signed-off-by: Dotan Barak <dotanb@mellanox.co.il> Signed-off-by: Roland Dreier <rolandd@cisco.com>
-rw-r--r--src/device.c3
-rw-r--r--src/sysfs.c3
2 files changed, 4 insertions, 2 deletions
diff --git a/src/device.c b/src/device.c
index 7c0184a..90e3b15 100644
--- a/src/device.c
+++ b/src/device.c
@@ -110,7 +110,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 df94516..a22442c 100644
--- a/src/sysfs.c
+++ b/src/sysfs.c
@@ -81,7 +81,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) {