Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3329374pxj; Mon, 24 May 2021 04:20:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1+1a9x9cSAN1K6tSAxrDAT/YBL++ZxQrz/9FbnkJ7oRo+6F9l21MlVn0Oom2rhdagLp58 X-Received: by 2002:a17:906:c218:: with SMTP id d24mr22231759ejz.363.1621855217142; Mon, 24 May 2021 04:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621855217; cv=none; d=google.com; s=arc-20160816; b=yzXqg3ruAOmyMqIZZR6MS9HlRa31ILjLag3WOSO38eVXqTAgIPNb9qV/gDTlcRLObT UVvJxl2+d2LYvKQYy9jDqRpgBWwbFL1hP6bhg5nnZbP4coC8ek5YuJUeKcnvd+ydPInX Nr36wHuEOJzch9kXAvCgr7hC86wrD3ABzg+Aul9EKSyLriRBE01Ovum8w7J0nhWmji9/ OYxvvfDHWMHbS+gwZBWhKqS0ldYdrs5py4p0tIcTBNQdvdVoQ6CCm72GRconvGYBwhRb T63SP1JPyrSSnXDT5bhH9f3a/rbWvAOfct3nUV/81OPy1UOFluz1n27b4hyYmmVuaT0i zwxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:references:cc:to:from :subject; bh=FR8Ikek8pyARnNOA1Me9kfohgwRdwZ3voGKJT+3Pczk=; b=xG0A/HaaFSEEGrOlSMZ038J5Z+AXccFV52X0xaunar6yCqXulnS/4gp/45X3SfT17J E3twwrIxDNgb1LZ+UWdKtwClW5YvRB4f7BXr/sy4XeRNaf3fr52n9v2jGGWf5t0B2Jre kijpzvE+F6P7bie6gu6EJWMVGgmDntFl96jtsxI+Dh6o06wVAQ0lFf1nMhylKXqFiKvv aL7TzkuDezWUcm12oYD5elj8DVZeIHwt8VuCwQqCigPJ3tMz9UQ50IoaCr8BlZ4xg2ca xyOeNshZS+B/RUOPt0BPvT0SV+T4RXG7v1mqAYFF0cOK3GuVVQoUNcVwJS1gAyh/96BP tYIg== 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 p8si14543871edj.611.2021.05.24.04.19.53; Mon, 24 May 2021 04:20:17 -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 S232584AbhEXLVS (ORCPT + 99 others); Mon, 24 May 2021 07:21:18 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5534 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232516AbhEXLVS (ORCPT ); Mon, 24 May 2021 07:21:18 -0400 Received: from dggems705-chm.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FpZRZ3xBdzkYvn for ; Mon, 24 May 2021 19:16:58 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggems705-chm.china.huawei.com (10.3.19.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:19:48 +0800 Received: from [10.174.179.184] (10.174.179.184) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:19:48 +0800 Subject: [PATCH 01/12] profile_create_node: set magic before strdup(name) to avoid memory leak From: Wu Guanghao To: CC: , References: <266bc52e-e279-ce84-0e1f-1405b9bc6174@huawei.com> Message-ID: Date: Mon, 24 May 2021 19:19:48 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.2.1 MIME-Version: 1.0 In-Reply-To: <266bc52e-e279-ce84-0e1f-1405b9bc6174@huawei.com> Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.184] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If new->magic != PROF_MAGIC_NODE, profile_free_node() don't free node. This will cause the node to be unable to be released correctly and a memory leak will occur. Signed-off-by: Wu Guanghao Signed-off-by: Zhiqiang Liu Reviewed-by: Wu Bo --- lib/support/profile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/support/profile.c b/lib/support/profile.c index 585ed595..2eb3a9d1 100644 --- a/lib/support/profile.c +++ b/lib/support/profile.c @@ -1093,6 +1093,8 @@ errcode_t profile_create_node(const char *name, const char *value, if (!new) return ENOMEM; memset(new, 0, sizeof(struct profile_node)); + new->magic = PROF_MAGIC_NODE; + new->name = strdup(name); if (new->name == 0) { profile_free_node(new); @@ -1105,7 +1107,6 @@ errcode_t profile_create_node(const char *name, const char *value, return ENOMEM; } } - new->magic = PROF_MAGIC_NODE; *ret_node = new; return 0; --