btrfs-progs: subvol show: reset subvol_path to NULL after free

User reported that 'btrfs subvolume show -u -- /mnt' causes double free.

Pointer subvol_path was freed in iterations but still keeps the old
value.  In the last iteration, error BTRFS_UTIL_ERROR_STOP_ITERATION
returned, then the double free of subvol_path happens in the out goto
label.

Set subvol_path to NULL after each free() in the loop to fix the issue.

Issue: #317
Signed-off-by: Su Yue <l@damenly.su>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Su Yue 2020-12-07 17:07:55 +08:00 committed by David Sterba
parent ffd1601236
commit b431ee33e8

View File

@ -1117,6 +1117,7 @@ static int cmd_subvol_show(const struct cmd_struct *cmd, int argc, char **argv)
break;
free(subvol_path);
subvol_path = NULL;
}
btrfs_util_destroy_subvolume_iterator(iter);
} else {