Reviewed-by: Nickle Wang <nick...@nvidia.com>

Regards,
Nickle

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Mike
> Maslenkin via groups.io
> Sent: Sunday, March 10, 2024 6:42 PM
> To: devel@edk2.groups.io
> Cc: Mike Maslenkin <mike.maslen...@gmail.com>; Abner Chang
> <abner.ch...@amd.com>; Igor Kulchytskyy <ig...@ami.com>; Nickle Wang
> <nick...@nvidia.com>
> Subject: [edk2-devel] [PATCH 3/4][edk2-redfish-client] RedfishClientPkg: fix 
> leak
> in provisioning properties functions
> 
> External email: Use caution opening links or attachments
> 
> 
> The structure instance retunred by ToStructure() must be deallocated properly.
> 
> Cc: Abner Chang <abner.ch...@amd.com>
> Cc: Igor Kulchytskyy <ig...@ami.com>
> Cc: Nickle Wang <nick...@nvidia.com>
> Signed-off-by: Mike Maslenkin <mike.maslen...@gmail.com>
> ---
>  .../v1_13_0/Common/ComputerSystemCommon.c     | 25 +++++++++++++------
>  .../v1_5_0/Common/ComputerSystemCommon.c      | 25 +++++++++++++------
>  2 files changed, 36 insertions(+), 14 deletions(-)
> 
> diff --git
> a/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Common/ComputerSyst
> emCommon.c
> b/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Common/ComputerSyst
> emCommon.c
> index df22a1c90c46..4795e4d6c6eb 100644
> ---
> a/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Common/ComputerSyst
> emCommon.c
> +++
> b/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Common/ComputerSy
> +++ stemCommon.c
> @@ -263,7 +263,7 @@ ProvisioningComputerSystemProperties (
>                                                );
> 
>    if (EFI_ERROR (Status)) {
> 
>      DEBUG ((DEBUG_ERROR, "%a: ToStructure failure: %r\n", __func__, Status));
> 
> -    return Status;
> 
> +    goto ON_RELEASE;
> 
>    }
> 
> 
> 
>    ComputerSystemCs = ComputerSystem->ComputerSystem;
> 
> @@ -365,7 +365,7 @@ ProvisioningComputerSystemProperties (
>                                   );
> 
>    if (EFI_ERROR (Status)) {
> 
>      DEBUG ((DEBUG_ERROR, "%a: ToJson() failed: %r\n", __func__, Status));
> 
> -    return Status;
> 
> +    goto ON_RELEASE;
> 
>    }
> 
> 
> 
>    if (PropertyChanged) {
> 
> @@ -374,10 +374,14 @@ ProvisioningComputerSystemProperties (
>      if (EFI_ERROR (Status)) {
> 
>        DEBUG ((DEBUG_ERROR, "%a: Fail to remove Redfish unchangeable
> properties from ResultJson.\n", __func__));
> 
>        *ResultJson = NULL;
> 
> -      return Status;
> 
> +      goto ON_RELEASE;
> 
>      }
> 
>    }
> 
> 
> 
> +  Status = EFI_SUCCESS;
> 
> +
> 
> +ON_RELEASE:
> 
> +
> 
>    //
> 
>    // Release resource.
> 
>    //
> 
> @@ -393,10 +397,17 @@ ProvisioningComputerSystemProperties (
>      DestoryRedfishCharArray (ComputerSystemCsEmpty->Boot->BootOrder,
> ArraySize);
> 
>    }
> 
> 
> 
> -  JsonStructProtocol->DestoryStructure (
> 
> -                        JsonStructProtocol,
> 
> -                        (EFI_REST_JSON_STRUCTURE_HEADER *)ComputerSystemEmpty
> 
> -                        );
> 
> +  if (ComputerSystemEmpty != NULL) {
> 
> +    JsonStructProtocol->DestoryStructure (
> 
> +                          JsonStructProtocol,
> 
> +                          (EFI_REST_JSON_STRUCTURE_HEADER
> + *)ComputerSystemEmpty
> 
> +                          );
> 
> +  }
> 
> +
> 
> +  if (EFI_ERROR (Status)) {
> 
> +    return Status;
> 
> +  }
> 
> +
> 
>    return (PropertyChanged ? EFI_SUCCESS : EFI_NOT_FOUND);
> 
>  }
> 
> 
> 
> diff --git
> a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Common/ComputerSyste
> mCommon.c
> b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Common/ComputerSyste
> mCommon.c
> index c383cad59029..2d257e01da2b 100644
> ---
> a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Common/ComputerSyste
> mCommon.c
> +++
> b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Common/ComputerSys
> +++ temCommon.c
> @@ -793,7 +793,7 @@ ProvisioningComputerSystemProperties (
>                                                );
> 
>    if (EFI_ERROR (Status)) {
> 
>      DEBUG ((DEBUG_ERROR, "%a: ToStructure failure: %r\n", __func__, Status));
> 
> -    return Status;
> 
> +    goto ON_RELEASE;
> 
>    }
> 
> 
> 
>    ComputerSystemCs = ComputerSystem->ComputerSystem;
> 
> @@ -1235,7 +1235,7 @@ ProvisioningComputerSystemProperties (
>                                   );
> 
>    if (EFI_ERROR (Status)) {
> 
>      DEBUG ((DEBUG_ERROR, "%a: ToJson() failed: %r\n", __func__, Status));
> 
> -    return Status;
> 
> +    goto ON_RELEASE;
> 
>    }
> 
> 
> 
>    if (PropertyChanged) {
> 
> @@ -1244,10 +1244,14 @@ ProvisioningComputerSystemProperties (
>      if (EFI_ERROR (Status)) {
> 
>        DEBUG ((DEBUG_ERROR, "%a: Fail to remove Redfish unchangeable
> properties from ResultJson.\n", __func__));
> 
>        *ResultJson = NULL;
> 
> -      return Status;
> 
> +      goto ON_RELEASE;
> 
>      }
> 
>    }
> 
> 
> 
> +  Status = EFI_SUCCESS;
> 
> +
> 
> +ON_RELEASE:
> 
> +
> 
>    //
> 
>    // Release resource.
> 
>    //
> 
> @@ -1263,10 +1267,17 @@ ProvisioningComputerSystemProperties (
>      DestoryRedfishCharArray (ComputerSystemCsEmpty->Boot->BootOrder,
> ArraySize);
> 
>    }
> 
> 
> 
> -  JsonStructProtocol->DestoryStructure (
> 
> -                        JsonStructProtocol,
> 
> -                        (EFI_REST_JSON_STRUCTURE_HEADER *)ComputerSystemEmpty
> 
> -                        );
> 
> +  if (ComputerSystemEmpty != NULL) {
> 
> +    JsonStructProtocol->DestoryStructure (
> 
> +                          JsonStructProtocol,
> 
> +                          (EFI_REST_JSON_STRUCTURE_HEADER
> + *)ComputerSystemEmpty
> 
> +                          );
> 
> +  }
> 
> +
> 
> +  if (EFI_ERROR (Status)) {
> 
> +    return Status;
> 
> +  }
> 
> +
> 
>    return (PropertyChanged ? EFI_SUCCESS : EFI_NOT_FOUND);
> 
>  }
> 
> 
> 
> --
> 2.32.0 (Apple Git-132)
> 
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#116567): https://edk2.groups.io/g/devel/message/116567
> Mute This Topic: https://groups.io/mt/104841894/7129762
> Group Owner: devel+ow...@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [nick...@nvidia.com] -=-=-
> =-=-=-=
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#116626): https://edk2.groups.io/g/devel/message/116626
Mute This Topic: https://groups.io/mt/104841894/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to