Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp126605pxv; Wed, 30 Jun 2021 01:28:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxf+zHIuH/CQD62Z9IzkUafHvUJJwPhcUWfBobZO1PzZAljLVll6Yu2arrq7nie3/g9lNmS X-Received: by 2002:a92:c612:: with SMTP id p18mr24466557ilm.54.1625041690471; Wed, 30 Jun 2021 01:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625041690; cv=none; d=google.com; s=arc-20160816; b=EhPI/1SgT/RAK5oVYzBgU4zku4ChR/Zuz2t5Ngh/MlH+16rz3PrK1RQ1pYgMD4RHuT 9gIcgVAOSS2Q2LfZIDfKuxBfQk5mWaIoZsXga7Tpmoj8XHcSuce67Ww7W0yXTTVZVQey 8/3FCncBHCKAVRHS6WbfTlC3BlHYET4nsd08TJmnquYH4t3wL1ywKUllx32V1JUv8U7N 9FKeC8HUMwEyt74nwlLwIlUfkMdxAAG4lFiHwHGVN1e13hEK58ajjBbuQElkeSEi5Kun c0W3HAzqiOfTqxDf9V9vUX7rPnHfxvqJoJVNqvCEEyZiKY6EvcqMGMbP/bfgGTMsqJ+h 7rxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=2bcvV3Qz/hPk/ATOcWRL6aqy9Lv06OcceEVR021cv+4=; b=loaEQVkSFT/g74NquMdSSnROf2OohipVOYBt3g8wycTVdCcTQUsotvh+4eDqccW5TC JsWt1vpqkx3nvOL/aFRMyI2qNIJdC4IGBMUh3B/T4P0880AvVFJB3/ESy74BGK89qK7j fehKFXA1ABMlokxQrJy1k/HJjw/gcXbA6lZlUDXP5Hjol/XuN+0T9QQ6m0FFwCh8IGU2 pKERNa0uM4pFACLavESWMfJXvayKlVYei1VOhkfrLqUAFuMhacHewj1q4Zr8q2OuGqLB aBOljobm/bFQt5GDSM2/6sZVXBNgiaJsy+IAVaoGv6gE2jVn4n+Gu5MLtMJ6ZAfonsh4 4XtQ== 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 u15si6283645ill.15.2021.06.30.01.27.58; Wed, 30 Jun 2021 01:28:10 -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 S233089AbhF3IaQ (ORCPT + 99 others); Wed, 30 Jun 2021 04:30:16 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:9326 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233519AbhF3IaN (ORCPT ); Wed, 30 Jun 2021 04:30:13 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GFDrL13qQz74H7 for ; Wed, 30 Jun 2021 16:23:30 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 30 Jun 2021 16:27:31 +0800 Received: from huawei.com (10.175.104.170) 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; Wed, 30 Jun 2021 16:27:30 +0800 From: wuguanghao To: , CC: , , Subject: [PATCH v2 01/12] profile_create_node: set magic before strdup(name) to avoid memory leak Date: Wed, 30 Jun 2021 16:27:13 +0800 Message-ID: <20210630082724.50838-2-wuguanghao3@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.170] 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; -- 2.19.1