From: Darrick J. Wong Date: Thu, 12 Dec 2013 17:43:36 +0000 (-0500) Subject: debugfs: fix various minor bogosity X-Git-Tag: v1.42.9~84 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;ds=sidebyside;h=50295a3f9e40894316301bebcc7247e9ec85f506;p=thirdparty%2Fe2fsprogs.git debugfs: fix various minor bogosity We should really use the ext2fs memory allocator functions in copy_file(), and we really should return a value if there's allocation problems. Also fix up a minor bogosity in an error message. Reviewed-by: Zheng Liu Cc: Robert Yang Cc: Darren Hart Signed-off-by: Darrick J. Wong Signed-off-by: "Theodore Ts'o" --- diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index f8701290c..ca0570ac5 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -1590,16 +1590,17 @@ static errcode_t copy_file(int fd, ext2_ino_t newfile, int bufsize, int make_hol if (retval) return retval; - if (!(buf = (char *) malloc(bufsize))){ - com_err("copy_file", errno, "can't allocate buffer\n"); - return; + retval = ext2fs_get_mem(bufsize, &buf); + if (retval) { + com_err("copy_file", retval, "can't allocate buffer\n"); + return retval; } /* This is used for checking whether the whole block is zero */ retval = ext2fs_get_memzero(bufsize, &zero_buf); if (retval) { com_err("copy_file", retval, "can't allocate buffer\n"); - free(buf); + ext2fs_free_mem(&buf); return retval; } @@ -1637,13 +1638,13 @@ static errcode_t copy_file(int fd, ext2_ino_t newfile, int bufsize, int make_hol ptr += written; } } - free(buf); + ext2fs_free_mem(&buf); ext2fs_free_mem(&zero_buf); retval = ext2fs_file_close(e2_file); return retval; fail: - free(buf); + ext2fs_free_mem(&buf); ext2fs_free_mem(&zero_buf); (void) ext2fs_file_close(e2_file); return retval; @@ -2101,7 +2102,7 @@ void do_bmap(int argc, char *argv[]) errcode = ext2fs_bmap2(current_fs, ino, 0, 0, 0, blk, 0, &pblk); if (errcode) { - com_err("argv[0]", errcode, + com_err(argv[0], errcode, "while mapping logical block %llu\n", blk); return; }