From patchwork Thu Oct 26 08:32:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Fengqi X-Patchwork-Id: 10027775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4A5156032C for ; Thu, 26 Oct 2017 08:33:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A5B328D48 for ; Thu, 26 Oct 2017 08:33:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DACB28D60; Thu, 26 Oct 2017 08:33:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D97ED28D48 for ; Thu, 26 Oct 2017 08:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932354AbdJZIdc (ORCPT ); Thu, 26 Oct 2017 04:33:32 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:39247 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932286AbdJZIda (ORCPT ); Thu, 26 Oct 2017 04:33:30 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="29632213" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Oct 2017 16:33:27 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id B612347F13C2 for ; Thu, 26 Oct 2017 16:33:24 +0800 (CST) Received: from localhost.localdomain (10.167.226.155) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 26 Oct 2017 16:33:23 +0800 From: Lu Fengqi To: Subject: [PATCH] btrfs-progs: qgroup: fix qgroup show sort by multi items Date: Thu, 26 Oct 2017 16:32:51 +0800 Message-ID: <20171026083251.13454-1-lufq.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 X-Originating-IP: [10.167.226.155] X-yoursite-MailScanner-ID: B612347F13C2.AA5B4 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lufq.fnst@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- qgroup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qgroup.c b/qgroup.c index fffdbb12..7e8ef079 100644 --- 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: