Thanks for catching this.
Reviewed-by: Abner Chang <abner.chang@hpe.com>
> -----Original Message-----
> From: Wenyi Xie <xiewenyi2@huawei.com>
> Sent: Thursday, March 10, 2022 7:26 PM
> To: devel@edk2.groups.io; Chang, Abner (HPS SW/FW Technologist)
> <abner.chang@hpe.com>; Wang, Nickle (Server BIOS)
> <nickle.wang@hpe.com>
> Cc: songdongkuang@huawei.com; xiewenyi2@huawei.com
> Subject: [PATCH EDK2 v1 1/1] RedfishPkg: fix memory leak issue
>
> The calloc memory is not free when function collectionEvalOp
> return in the halfway.
>
> Cc: Abner Chang <abner.chang@hpe.com>
> Cc: Nickle Wang <nickle.wang@hpe.com>
> Signed-off-by: Wenyi Xie <xiewenyi2@huawei.com>
> ---
> 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