use xmalloc instead of malloc
This commit is contained in:
parent
7fde8debc4
commit
d5826903c1
@ -46,14 +46,8 @@ static void add_to_dirlist(const char *name, struct dir_list **list)
|
|||||||
{
|
{
|
||||||
struct dir_list *dp;
|
struct dir_list *dp;
|
||||||
|
|
||||||
dp = malloc(sizeof(struct dir_list));
|
dp = xmalloc(sizeof(struct dir_list));
|
||||||
if (!dp)
|
dp->name = xmalloc(strlen(name)+1);
|
||||||
return;
|
|
||||||
dp->name = malloc(strlen(name)+1);
|
|
||||||
if (!dp->name) {
|
|
||||||
free(dp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
strcpy(dp->name, name);
|
strcpy(dp->name, name);
|
||||||
dp->next = *list;
|
dp->next = *list;
|
||||||
*list = dp;
|
*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))
|
if (S_ISDIR(st.st_mode))
|
||||||
add_to_dirlist(path, list);
|
add_to_dirlist(path, list);
|
||||||
if (S_ISBLK(st.st_mode) && st.st_rdev == device) {
|
if (S_ISBLK(st.st_mode) && st.st_rdev == device) {
|
||||||
cp = malloc(strlen(path)+1);
|
cp = xmalloc(strlen(path)+1);
|
||||||
if (!cp) {
|
|
||||||
closedir(dir);
|
|
||||||
return ENOMEM;
|
|
||||||
}
|
|
||||||
strcpy(cp, path);
|
strcpy(cp, path);
|
||||||
*ret_path = cp;
|
*ret_path = cp;
|
||||||
goto success;
|
goto success;
|
||||||
|
@ -66,9 +66,7 @@ errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags)
|
|||||||
ssize_t actual;
|
ssize_t actual;
|
||||||
errcode_t retval;
|
errcode_t retval;
|
||||||
|
|
||||||
buf = malloc(fs->blocksize * BUF_BLOCKS);
|
buf = xmalloc(fs->blocksize * BUF_BLOCKS);
|
||||||
if (!buf)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
for (group = 0; group < fs->group_desc_count; group++) {
|
for (group = 0; group < fs->group_desc_count; group++) {
|
||||||
blk = fs->group_desc[(unsigned)group].bg_inode_table;
|
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;
|
ssize_t actual;
|
||||||
errcode_t retval;
|
errcode_t retval;
|
||||||
|
|
||||||
buf = malloc(fs->blocksize * BUF_BLOCKS);
|
buf = xmalloc(fs->blocksize * BUF_BLOCKS);
|
||||||
if (!buf)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
for (group = 0; group < fs->group_desc_count; group++) {
|
for (group = 0; group < fs->group_desc_count; group++) {
|
||||||
blk = fs->group_desc[(unsigned)group].bg_inode_table;
|
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;
|
ssize_t actual;
|
||||||
errcode_t retval;
|
errcode_t retval;
|
||||||
|
|
||||||
buf = malloc(fs->blocksize);
|
buf = xmalloc(fs->blocksize);
|
||||||
if (!buf)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write out the superblock
|
* Write out the superblock
|
||||||
@ -238,9 +232,7 @@ errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd,
|
|||||||
errcode_t retval;
|
errcode_t retval;
|
||||||
|
|
||||||
size = fs->blocksize * (fs->group_desc_count + 1);
|
size = fs->blocksize * (fs->group_desc_count + 1);
|
||||||
buf = malloc(size);
|
buf = xmalloc(size);
|
||||||
if (!buf)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read it all in.
|
* 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;
|
size = size * fs->group_desc_count;
|
||||||
|
|
||||||
buf = malloc(size);
|
buf = xmalloc(size);
|
||||||
if (!buf)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
actual = read(fd, buf, size);
|
actual = read(fd, buf, size);
|
||||||
if (actual == -1) {
|
if (actual == -1) {
|
||||||
|
@ -641,9 +641,7 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
|
|||||||
length = EXT2_INODE_SIZE(fs->super);
|
length = EXT2_INODE_SIZE(fs->super);
|
||||||
|
|
||||||
if (length > (int) sizeof(struct ext2_inode_large)) {
|
if (length > (int) sizeof(struct ext2_inode_large)) {
|
||||||
w_inode = malloc(length);
|
w_inode = xmalloc(length);
|
||||||
if (!w_inode)
|
|
||||||
return ENOMEM;
|
|
||||||
} else
|
} else
|
||||||
w_inode = &temp_inode;
|
w_inode = &temp_inode;
|
||||||
memset(w_inode, 0, length);
|
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,
|
return ext2fs_write_inode_full(fs, ino, inode,
|
||||||
sizeof(struct ext2_inode));
|
sizeof(struct ext2_inode));
|
||||||
|
|
||||||
buf = malloc(size);
|
buf = xmalloc(size);
|
||||||
if (!buf)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
memset(buf, 0, size);
|
memset(buf, 0, size);
|
||||||
*buf = *inode;
|
*buf = *inode;
|
||||||
|
Loading…
Reference in New Issue
Block a user