use xmalloc instead of malloc
authorMike Frysinger <vapier@gentoo.org>
Sun, 12 Jun 2005 00:45:09 +0000 (00:45 -0000)
committerMike Frysinger <vapier@gentoo.org>
Sun, 12 Jun 2005 00:45:09 +0000 (00:45 -0000)
e2fsprogs/ext2fs/finddev.c
e2fsprogs/ext2fs/imager.c
e2fsprogs/ext2fs/inode.c

index fa2cadde45ce57c4f7cdc9c28086c95cf3880ad1..c459c083321701384b9f571c47462e0171484018 100644 (file)
@@ -46,14 +46,8 @@ static void add_to_dirlist(const char *name, struct dir_list **list)
 {
        struct dir_list *dp;
 
-       dp = malloc(sizeof(struct dir_list));
-       if (!dp)
-               return;
-       dp->name = malloc(strlen(name)+1);
-       if (!dp->name) {
-               free(dp);
-               return;
-       }
+       dp = xmalloc(sizeof(struct dir_list));
+       dp->name = xmalloc(strlen(name)+1);
        strcpy(dp->name, name);
        dp->next = *list;
        *list = dp;
@@ -100,11 +94,7 @@ static int scan_dir(char *dir_name, dev_t device, struct dir_list **list,
                if (S_ISDIR(st.st_mode))
                        add_to_dirlist(path, list);
                if (S_ISBLK(st.st_mode) && st.st_rdev == device) {
-                       cp = malloc(strlen(path)+1);
-                       if (!cp) {
-                               closedir(dir);
-                               return ENOMEM;
-                       }
+                       cp = xmalloc(strlen(path)+1);
                        strcpy(cp, path);
                        *ret_path = cp;
                        goto success;
index 596fbbebe002f4d1ee3206d27c722bde8aa77105..3f2826b8206ef109e91dc8de8d99d534502b6369 100644 (file)
@@ -66,9 +66,7 @@ errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags)
        ssize_t         actual;
        errcode_t       retval;
 
-       buf = malloc(fs->blocksize * BUF_BLOCKS);
-       if (!buf)
-               return ENOMEM;
+       buf = xmalloc(fs->blocksize * BUF_BLOCKS);
        
        for (group = 0; group < fs->group_desc_count; group++) {
                blk = fs->group_desc[(unsigned)group].bg_inode_table;
@@ -138,9 +136,7 @@ errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd,
        ssize_t         actual;
        errcode_t       retval;
 
-       buf = malloc(fs->blocksize * BUF_BLOCKS);
-       if (!buf)
-               return ENOMEM;
+       buf = xmalloc(fs->blocksize * BUF_BLOCKS);
        
        for (group = 0; group < fs->group_desc_count; group++) {
                blk = fs->group_desc[(unsigned)group].bg_inode_table;
@@ -187,9 +183,7 @@ errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd,
        ssize_t         actual;
        errcode_t       retval;
 
-       buf = malloc(fs->blocksize);
-       if (!buf)
-               return ENOMEM;
+       buf = xmalloc(fs->blocksize);
 
        /*
         * Write out the superblock
@@ -238,9 +232,7 @@ errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd,
        errcode_t       retval;
 
        size = fs->blocksize * (fs->group_desc_count + 1);
-       buf = malloc(size);
-       if (!buf)
-               return ENOMEM;
+       buf = xmalloc(size);
 
        /*
         * Read it all in.
@@ -364,9 +356,7 @@ errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags)
        }
        size = size * fs->group_desc_count;
 
-       buf = malloc(size);
-       if (!buf)
-               return ENOMEM;
+       buf = xmalloc(size);
 
        actual = read(fd, buf, size);
        if (actual == -1) {
index 222568ebe74850fa402e191a425a767b8a9fa4a3..30580bf6d67c911ec1f982e290e6c4f2de196bd1 100644 (file)
@@ -641,9 +641,7 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
                length = EXT2_INODE_SIZE(fs->super);
 
        if (length > (int) sizeof(struct ext2_inode_large)) {
-               w_inode = malloc(length);
-               if (!w_inode)
-                       return ENOMEM;
+               w_inode = xmalloc(length);
        } else
                w_inode = &temp_inode;
        memset(w_inode, 0, length);
@@ -731,9 +729,7 @@ errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
                return ext2fs_write_inode_full(fs, ino, inode,
                                               sizeof(struct ext2_inode));
 
-       buf = malloc(size);
-       if (!buf)
-               return ENOMEM;
+       buf = xmalloc(size);
 
        memset(buf, 0, size);
        *buf = *inode;