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>
This commit is contained in:
Qu Wenruo 2024-06-04 13:47:53 +09:30 committed by David Sterba
parent 5644dc5d18
commit fd5a80e5bf

View file

@ -70,7 +70,7 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
if (ret < 0) {
errno = -ret;
error("cannot read bytenr %llu: %m", logical);
return ret;
goto out;
}
printf("corrupting %llu copy %d\n", logical, mirror_num);
memset(buf, 0, sectorsize);
@ -78,7 +78,7 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
if (ret < 0) {
errno = -ret;
error("cannot write bytenr %llu: %m", logical);
return ret;
goto out;
}
}
@ -90,7 +90,8 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
if (mirror_num > num_copies)
break;
}
out:
free(buf);
return 0;
}