From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mx.groups.io with SMTP id smtpd.web12.8433.1646911594171021802 for ; Thu, 10 Mar 2022 03:26:34 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.187, mailfrom: xiewenyi2@huawei.com) Received: from kwepemi100025.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KDmq93zjRzcZy8; Thu, 10 Mar 2022 19:21:41 +0800 (CST) Received: from kwepemm600004.china.huawei.com (7.193.23.242) by kwepemi100025.china.huawei.com (7.221.188.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Thu, 10 Mar 2022 19:26:31 +0800 Received: from kwephisprg16640.huawei.com (10.247.83.252) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 10 Mar 2022 19:26:31 +0800 From: "wenyi,xie" To: , , CC: , Subject: [PATCH EDK2 v1 1/1] RedfishPkg: fix memory leak issue Date: Thu, 10 Mar 2022 19:25:34 +0800 Message-ID: <20220310112534.2952545-2-xiewenyi2@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20220310112534.2952545-1-xiewenyi2@huawei.com> References: <20220310112534.2952545-1-xiewenyi2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.247.83.252] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected Content-Type: text/plain The calloc memory is not free when function collectionEvalOp return in the halfway. Cc: Abner Chang Cc: Nickle Wang Signed-off-by: Wenyi Xie --- RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c index 3f2b83e834d0..6c6e2246abe3 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/payload.c @@ -620,6 +620,7 @@ collectionEvalOp ( if (((*StatusCode == NULL) && (members == NULL)) || ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)))) { + free (valid); return members; } @@ -633,6 +634,7 @@ collectionEvalOp ( if (((*StatusCode == NULL) && (tmp == NULL)) || ((*StatusCode != NULL) && ((**StatusCode < HTTP_STATUS_200_OK) || (**StatusCode > HTTP_STATUS_206_PARTIAL_CONTENT)))) { + free (valid); return tmp; } @@ -658,19 +660,15 @@ collectionEvalOp ( cleanupPayload (members); if (validCount == 0) { - free (valid); - return NULL; - } - - if (validCount == 1) { + ret = NULL; + } else if (validCount == 1) { ret = valid[0]; - free (valid); - return ret; } else { ret = createCollection (payload->service, validCount, valid); - free (valid); - return ret; } + + free (valid); + return ret; } static redfishPayload * -- 2.20.1.windows.1