btrfs-progs: qgroup: fix qgroup show sort by multi items
authorLu Fengqi <lufq.fnst@cn.fujitsu.com>
Thu, 26 Oct 2017 08:32:51 +0000 (16:32 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 14 Nov 2017 14:59:00 +0000 (15:59 +0100)
We should not free the string until we don't call strtok any longer.

If the string is freed in advance, in fact, the second and subsequent
sort items will be ignored.

Fixes: 9fcdf8f8945b ("btrfs-progs: don't write to optarg in btrfs_qgroup_parse_sort_string")
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
qgroup.c

index fffdbb1..7e8ef07 100644 (file)
--- a/qgroup.c
+++ b/qgroup.c
@@ -1222,7 +1222,8 @@ int btrfs_qgroup_parse_sort_string(const char *opt_arg,
        if (!opt_tmp)
                return -ENOMEM;
 
-       while ((p = strtok(opt_tmp, ",")) != NULL) {
+       p = strtok(opt_tmp, ",");
+       while (p) {
                flag = 0;
                ptr_argv = all_sort_items;
 
@@ -1262,8 +1263,7 @@ int btrfs_qgroup_parse_sort_string(const char *opt_arg,
                        }
                        btrfs_qgroup_setup_comparer(comps, what_to_sort, order);
                }
-               free(opt_tmp);
-               opt_tmp = NULL;
+               p = strtok(NULL, ",");
        }
 
 out: