Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1850870pxv; Fri, 16 Jul 2021 20:11:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdNP0WVgMGTgq+0uSZyuKFkQQnoW924E+fOFN/oah7XHpfaPuXEydMVqJKt6BD+GhxfIwk X-Received: by 2002:a05:6402:1812:: with SMTP id g18mr18648968edy.325.1626491465034; Fri, 16 Jul 2021 20:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626491465; cv=none; d=google.com; s=arc-20160816; b=PfBkwZczrsdbYj60HjoFatZmmYOadOP77sB6xhTe2Oaln+S4/DR0xDqiWr5F1+ye4e 3/pKF7lY3ZR4xHQg569V3dD5eMpdpbEZ6tzINOX83/b1mfXOpXbeqYCxmFJnEmU/FCS6 KDYXKdJbqdp/DuJsYVaxzoO/lJcoiNKeZmWcrN4dj3+pX/VK6sr36gwXRPDh+y4YsSub kGfPxl2Xq2jvYOTpsYpHcnpz/7pqsBzeq3ccXaErththX879JBJRo7espXLo7q9ZrcML eTqaGY7pSuMvHx1VgmU3yBiWNC/ldKoKIlrNQ3x0m3w6l0PPfIAMRjgeN51ys+GtuPRU hfBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=cq/HoF+1GMSu6KyX0G1RBHJ3PofesuYlWPXHwl2bT8Q=; b=TVsXmDQXRj49jPg7PrCoR1ZEMLrvEnvYw4taHUUPDdG565PnA3VfsGYdWAg9QgYcT7 H2SLzpSnHYu/6S1FdFXUTg59YIl3Uv2AV3SXTO8YF9oIkHsUwBvVcGYgNxO5CsoNpSC1 vLwmJzs3kSTU2tAE2o3530Z0yKtxx5VzzNRO7SGChhZH2i4fA6zy4C1cKnZIXVxYJGX7 PIgPgfucpjUCMoTVswZtXqwkJhjsAMMSQSDtvTYFtowGO3SZghFoVJ6UPQak0vHsqfKj 42zC8FCF0kSVAghgOv6YCztOliiEswaZpmLRrx+lwf7KDwNbmz9I9lCKaPUmRK+QXZud yBoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y7si15139371ejm.617.2021.07.16.20.10.19; Fri, 16 Jul 2021 20:11:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232066AbhGQDNE (ORCPT + 99 others); Fri, 16 Jul 2021 23:13:04 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:11327 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbhGQDND (ORCPT ); Fri, 16 Jul 2021 23:13:03 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GRXzb4bhnz7tCn; Sat, 17 Jul 2021 11:05:31 +0800 (CST) Received: from dggema765-chm.china.huawei.com (10.1.198.207) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Sat, 17 Jul 2021 11:10:02 +0800 Received: from [127.0.0.1] (10.174.177.249) by dggema765-chm.china.huawei.com (10.1.198.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 17 Jul 2021 11:10:02 +0800 Subject: Re: [PATCH v2 04/12] ss_add_info_dir: fix memory leak and check whether To: "Theodore Y. Ts'o" , wuguanghao CC: , , References: <20210630082724.50838-2-wuguanghao3@huawei.com> <20210630082724.50838-5-wuguanghao3@huawei.com> From: Zhiqiang Liu Message-ID: Date: Sat, 17 Jul 2021 11:10:01 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.174.177.249] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggema765-chm.china.huawei.com (10.1.198.207) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On 2021/7/16 11:27, Theodore Y. Ts'o wrote: > On Wed, Jun 30, 2021 at 04:27:16PM +0800, wuguanghao wrote: >> In ss_add_info_dir(), need free info->info_dirs before return, >> otherwise it will cause memory leak. At the same time, it is necessary >> to check whether dirs[n_dirs] is a null pointer, otherwise a segmentation >> fault will occur. >> >> Signed-off-by: Wu Guanghao >> Signed-off-by: Zhiqiang Liu >> Reviewed-by: Wu Bo >> --- >> lib/ss/help.c | 5 +++++ >> 1 file changed, 5 insertions(+) >> >> diff --git a/lib/ss/help.c b/lib/ss/help.c >> index 5204401b..6768b9b1 100644 >> --- a/lib/ss/help.c >> +++ b/lib/ss/help.c >> @@ -148,6 +148,7 @@ void ss_add_info_dir(int sci_idx, char *info_dir, int *code_ptr) >> dirs = (char **)realloc((char *)dirs, >> (unsigned)(n_dirs + 2)*sizeof(char *)); >> if (dirs == (char **)NULL) { >> + free(info->info_dirs); >> info->info_dirs = (char **)NULL; >> *code_ptr = errno; >> return; > Adding the free() isn't right fix. The real problem is that this line > should be removed: > > info->info_dirs = (char **)NULL; > > The function is trying to add a string (a directory name) to list, and > the realloc() is trying to extend the list. If the realloc fils, we > shouldn't be zapping the original list. We should just be returning, > and leaving the original list of directories unchanged and untouched. > > - Ted Thanks for your patient reply. We will correct that in v3 patch. > > .