btrfs-progs: use on-stack buffer in __csum_tree_block_size
authorDavid Sterba <dsterba@suse.com>
Fri, 6 Nov 2015 16:50:48 +0000 (17:50 +0100)
committerDavid Sterba <dsterba@suse.com>
Fri, 13 Nov 2015 17:24:34 +0000 (18:24 +0100)
We know the maximum size of a checksum, calling malloc for 4 bytes is
weird.

Signed-off-by: David Sterba <dsterba@suse.com>
disk-io.c

index 139bc80..7a63b91 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -126,14 +126,10 @@ void btrfs_csum_final(u32 crc, char *result)
 static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
                                  int verify, int silent)
 {
-       char *result;
+       char result[BTRFS_CSUM_SIZE];
        u32 len;
        u32 crc = ~(u32)0;
 
-       result = malloc(csum_size * sizeof(char));
-       if (!result)
-               return 1;
-
        len = buf->len - BTRFS_CSUM_SIZE;
        crc = crc32c(crc, buf->data + BTRFS_CSUM_SIZE, len);
        btrfs_csum_final(crc, result);
@@ -145,13 +141,11 @@ static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
                                       (unsigned long long)buf->start,
                                       *((u32 *)result),
                                       *((u32*)(char *)buf->data));
-                       free(result);
                        return 1;
                }
        } else {
                write_extent_buffer(buf, result, 0, csum_size);
        }
-       free(result);
        return 0;
 }