From 2b175eeb6a3f630aef5a59a2c610a5be1a0cdd65 Mon Sep 17 00:00:00 2001 From: Wenyi Xie Date: Thu, 10 Mar 2022 17:02:14 +0800 Subject: [PATCH] RedfishPkg: fix memory leak issue The calloc memory is not free when function collectionEvalOp return in the halfway. Cc: Abner Chang Cc: Nickle Wang Signed-off-by: Wenyi Xie Reviewed-by: Abner Chang --- .../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 3f2b83e834..6c6e2246ab 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 *