btrfs-progs: mkfs: duplicate argument for --rootdir path

The source dir points to the argv data, we should make a copy to be sure
it won't change due to further processing.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2022-09-14 17:03:18 +02:00
parent 54fe8e648a
commit c33c2c66b3

View File

@ -1114,7 +1114,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
PACKAGE_STRING);
goto success;
case 'r':
source_dir = optarg;
free(source_dir);
source_dir = strdup(optarg);
source_dir_set = true;
break;
case 'U':
@ -1748,6 +1749,7 @@ out:
btrfs_close_all_devices();
free(label);
free(source_dir);
return !!ret;
error:
@ -1755,6 +1757,7 @@ error:
close(fd);
free(label);
free(source_dir);
exit(1);
success:
exit(0);