btrfs-progs: init uninitialized output buf for btrfs-restore
authorGui Hecheng <guihc.fnst@cn.fujitsu.com>
Thu, 21 Aug 2014 03:35:36 +0000 (11:35 +0800)
committerDavid Sterba <dsterba@suse.cz>
Sun, 14 Sep 2014 11:10:44 +0000 (13:10 +0200)
A memory problem reported by valgrind as follows:
=== Syscall param pwrite64(buf) points to uninitialised byte(s)
When running:
# valgrind --leak-check=yes btrfs restore /dev/sda9 /mnt/backup

Because the output buf size is alloced with malloc, but the length of
output data is shorter than the sizeof(buf), so valgrind report
uninitialised byte(s).
We could use calloc to repalce malloc and clear this WARNING away.

Reported-by: Marc Dietrich <marvin24@gmx.de>
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-restore.c

index dc6c027..e2bcbf9 100644 (file)
@@ -251,7 +251,7 @@ static int copy_one_inline(int fd, struct btrfs_path *path, u64 pos)
        }
 
        ram_size = btrfs_file_extent_ram_bytes(leaf, fi);
-       outbuf = malloc(ram_size);
+       outbuf = calloc(1, ram_size);
        if (!outbuf) {
                fprintf(stderr, "No memory\n");
                return -ENOMEM;
@@ -320,7 +320,7 @@ static int copy_one_extent(struct btrfs_root *root, int fd,
        }
 
        if (compress != BTRFS_COMPRESS_NONE) {
-               outbuf = malloc(ram_size);
+               outbuf = calloc(1, ram_size);
                if (!outbuf) {
                        fprintf(stderr, "No memory\n");
                        free(inbuf);