Skip to content

Commit fd5a80e

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: corrupt-block: fix memory leak in debug_corrupt_sector()
ASAN build (make D=asan) detects a memory leak in btrfs-corrupt-block inside debug_corrupt_sector(). This can be reproduced by fsck/013 test case. The cause is pretty simple, we just malloc a sector and forgot to free it. Issue: #806 Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 5644dc5 commit fd5a80e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

btrfs-corrupt-block.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
7070
if (ret < 0) {
7171
errno = -ret;
7272
error("cannot read bytenr %llu: %m", logical);
73-
return ret;
73+
goto out;
7474
}
7575
printf("corrupting %llu copy %d\n", logical, mirror_num);
7676
memset(buf, 0, sectorsize);
7777
ret = write_data_to_disk(fs_info, buf, logical, sectorsize);
7878
if (ret < 0) {
7979
errno = -ret;
8080
error("cannot write bytenr %llu: %m", logical);
81-
return ret;
81+
goto out;
8282
}
8383
}
8484

@@ -90,7 +90,8 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
9090
if (mirror_num > num_copies)
9191
break;
9292
}
93-
93+
out:
94+
free(buf);
9495
return 0;
9596
}
9697

0 commit comments

Comments
 (0)