[openib-general] [srptools] [PATCH] Added checks to memory allocation failure when using asprintf

Dotan Barak dotanb at dev.mellanox.co.il
Tue Jan 16 02:58:48 PST 2007


Added checks to memory allocation failure when using asprintf.

Signed-off-by: Dotan Barak <dotanb at mellanox.co.il>
---

Index: gen2_devel_user/src/userspace/srptools/src/srp-dm.c
===================================================================
--- gen2_devel_user.orig/src/userspace/srptools/src/srp-dm.c	2007-01-15 17:02:21.000000000 +0200
+++ gen2_devel_user/src/userspace/srptools/src/srp-dm.c	2007-01-16 10:07:47.000000000 +0200
@@ -128,7 +128,8 @@ static int read_file(const char *dir, co
 	int fd;
 	int len;
 
-	asprintf(&path, "%s/%s", dir, file);
+	if (asprintf(&path, "%s/%s", dir, file) < 0)
+		return -1;
 
 	fd = open(path, O_RDONLY);
 	if (fd < 0)
@@ -185,8 +186,11 @@ static int setup_port_sysfs_path(void) {
 		return -1;
 	}
 
-	asprintf(&port_sysfs_path, "%s/class/infiniband/%s/ports/%s",
-		 sysfs_path, ibdev, ibport);
+	if (asprintf(&port_sysfs_path, "%s/class/infiniband/%s/ports/%s",
+		 sysfs_path, ibdev, ibport) < 0) {
+		fprintf(stderr, "Couldn't allocate memory\n");
+		return -1;
+	}
 
 	return 0;
 }






More information about the general mailing list