[PATCH V4 06/14] kpartx: use xmalloc to instead of malloc in main func

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In main func of kpartx.c, we should check return value of
malloc before using it. So we use xmalloc to instead of
malloc.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@xxxxxxxxxx>
Signed-off-by: Lixiaokeng <lixiaokeng@xxxxxxxxxx>
---
 kpartx/kpartx.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index 98f6176e..4a0aae93 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -209,6 +209,23 @@ check_uuid(char *uuid, char *part_uuid, char **err_msg) {
 	return 0;
 }

+static void *
+xmalloc (size_t size) {
+	void *t;
+
+	if (size == 0)
+		return NULL;
+
+	t = malloc (size);
+
+	if (t == NULL) {
+		fprintf(stderr, "Out of memory\n");
+		exit(1);
+	}
+
+	return t;
+}
+
 int
 main(int argc, char **argv){
 	int i, j, m, n, op, off, arg, c, d, ro=0;
@@ -383,7 +400,7 @@ main(int argc, char **argv){
 		mapname = device + off;

 	if (delim == NULL) {
-		delim = malloc(DELIM_SIZE);
+		delim = xmalloc(DELIM_SIZE);
 		memset(delim, 0, DELIM_SIZE);
 		set_delimiter(mapname, delim);
 	}
@@ -670,23 +687,6 @@ end:
 	return r;
 }

-void *
-xmalloc (size_t size) {
-	void *t;
-
-	if (size == 0)
-		return NULL;
-
-	t = malloc (size);
-
-	if (t == NULL) {
-		fprintf(stderr, "Out of memory\n");
-		exit(1);
-	}
-
-	return t;
-}
-
 /*
  * sseek: seek to specified sector
  */
-- 

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel




[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux