Skip to content

Commit

Permalink
RedfishClientPkg/Features: release resources
Browse files Browse the repository at this point in the history
-Release Etag and PendingSettingUri resources.
-Update function header for GetHttpResponseEtag() and
GetHttpResponseLocation(). Caller has to release returned
memory buffer from these two functions.
-Fix typo.

Signed-off-by: Nickle Wang <[email protected]>
Cc: Abner Chang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
Cc: Nick Ramirez <[email protected]>
  • Loading branch information
nicklela committed Apr 1, 2024
1 parent e787790 commit e6b9610
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 48 deletions.
2 changes: 1 addition & 1 deletion RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ HandleResource (

//
// Check and see if target property exist or not even when collection member exists.
// If not, we sill do provision.
// If not, we still do provision.
//
DEBUG ((REDFISH_DEBUG_TRACE, "%a Check for %s\n", __func__, Uri));
Status = EdkIIRedfishResourceConfigCheck (&SchemaInfo, Uri, NULL);
Expand Down
20 changes: 16 additions & 4 deletions RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ RedfishResourceConsumeResource (
//
// Searching for etag in HTTP response header
//
Etag = NULL;
GetHttpResponseEtag (ExpectedResponse, &Etag);
Etag = NULL;
Status = GetHttpResponseEtag (ExpectedResponse, &Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __func__));
}

Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n", __func__, Private->Uri, Status));
Expand Down Expand Up @@ -338,8 +342,12 @@ RedfishResourceCheck (
//
// Find etag in HTTP response header
//
Etag = NULL;
GetHttpResponseEtag (&Response, &Etag);
Etag = NULL;
Status = GetHttpResponseEtag (&Response, &Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __func__));
}

Status = RedfishCheckResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to check resource from: %s: %r\n", __func__, Uri, Status));
Expand All @@ -348,6 +356,10 @@ RedfishResourceCheck (
//
// Release resource
//
if (Etag != NULL) {
FreePool (Etag);
}

RedfishHttpFreeResponse (&Response);
Private->Payload = NULL;

Expand Down
33 changes: 23 additions & 10 deletions RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ RedfishResourceConsumeResource (
//
// Check and see if "@Redfish.Settings" exist or not.
//
Status = GetPendingSettings (
Private->RedfishService,
Response.Payload,
&PendingSettingResponse,
&PendingSettingUri
);
PendingSettingUri = NULL;
Status = GetPendingSettings (
Private->RedfishService,
Response.Payload,
&PendingSettingResponse,
&PendingSettingUri
);
if (!EFI_ERROR (Status)) {
DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", __func__, PendingSettingUri));
SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
Expand All @@ -147,8 +148,12 @@ RedfishResourceConsumeResource (
//
// Find etag in HTTP response header
//
Etag = NULL;
GetHttpResponseEtag (ExpectedResponse, &Etag);
Etag = NULL;
Status = GetHttpResponseEtag (ExpectedResponse, &Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n", __func__, Private->Uri, Status));
Expand All @@ -170,6 +175,10 @@ RedfishResourceConsumeResource (
Private->Json = NULL;
}

if (PendingSettingUri != NULL) {
FreePool (PendingSettingUri);
}

return Status;
}

Expand Down Expand Up @@ -323,8 +332,12 @@ RedfishResourceCheck (
//
// Find etag in HTTP response header
//
Etag = NULL;
GetHttpResponseEtag (&Response, &Etag);
Etag = NULL;
Status = GetHttpResponseEtag (&Response, &Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Status = RedfishCheckResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: failed to check resource from: %s: %r\n", __func__, Uri, Status));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ HandleResource (

//
// Check and see if target property exist or not even when collection member exists.
// If not, we sill do provision.
// If not, we still do provision.
//
DEBUG ((REDFISH_BOOT_OPTION_COLLECTION_DEBUG_TRACE, "%a Check for %s\n", __func__, Uri));
Status = EdkIIRedfishResourceConfigCheck (&SchemaInfo, Uri, NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ RedfishResourceConsumeResource (
// Check and see if "@Redfish.Settings" exist or not.
//
ZeroMem (&PendingSettingResponse, sizeof (REDFISH_RESPONSE));
Status = GetPendingSettings (
Private->RedfishService,
Response.Payload,
&PendingSettingResponse,
&PendingSettingUri
);
PendingSettingUri = NULL;
Status = GetPendingSettings (
Private->RedfishService,
Response.Payload,
&PendingSettingResponse,
&PendingSettingUri
);
if (!EFI_ERROR (Status)) {
DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", __func__, PendingSettingUri));
SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
Expand All @@ -151,8 +152,12 @@ RedfishResourceConsumeResource (
//
// Find etag in HTTP response header
//
Etag = NULL;
GetHttpResponseEtag (ExpectedResponse, &Etag);
Etag = NULL;
Status = GetHttpResponseEtag (ExpectedResponse, &Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n", __func__, Private->Uri, Status));
Expand All @@ -177,6 +182,10 @@ RedfishResourceConsumeResource (
Private->Json = NULL;
}

if (PendingSettingUri != NULL) {
FreePool (PendingSettingUri);
}

return Status;
}

Expand Down Expand Up @@ -330,8 +339,12 @@ RedfishResourceCheck (
//
// Find etag in HTTP response header
//
Etag = NULL;
GetHttpResponseEtag (&Response, &Etag);
Etag = NULL;
Status = GetHttpResponseEtag (&Response, &Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Status = RedfishCheckResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to check resource from: %s: %r\n", __func__, Uri, Status));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ RedfishResourceConsumeResource (
// Check and see if "@Redfish.Settings" exist or not.
//
ZeroMem (&PendingSettingResponse, sizeof (REDFISH_RESPONSE));
Status = GetPendingSettings (
Private->RedfishService,
Response.Payload,
&PendingSettingResponse,
&PendingSettingUri
);
PendingSettingUri = NULL;
Status = GetPendingSettings (
Private->RedfishService,
Response.Payload,
&PendingSettingResponse,
&PendingSettingUri
);
if (!EFI_ERROR (Status)) {
DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", __func__, PendingSettingUri));
SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
Expand All @@ -152,8 +153,12 @@ RedfishResourceConsumeResource (
//
// Find etag in HTTP response header
//
Etag = NULL;
GetHttpResponseEtag (ExpectedResponse, &Etag);
Etag = NULL;
Status = GetHttpResponseEtag (ExpectedResponse, &Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n", __func__, Private->Uri, Status));
Expand All @@ -178,6 +183,10 @@ RedfishResourceConsumeResource (
Private->Json = NULL;
}

if (PendingSettingUri != NULL) {
FreePool (PendingSettingUri);
}

return Status;
}

Expand Down Expand Up @@ -331,8 +340,12 @@ RedfishResourceCheck (
//
// Find etag in HTTP response header
//
Etag = NULL;
GetHttpResponseEtag (&Response, &Etag);
Etag = NULL;
Status = GetHttpResponseEtag (&Response, &Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Status = RedfishCheckResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to check resource from: %s: %r\n", __func__, Uri, Status));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ HandleResource (

//
// Check and see if target property exist or not even when collection member exists.
// If not, we sill do provision.
// If not, we still do provision.
//
DEBUG ((REDFISH_DEBUG_TRACE, "%a Check for %s\n", __func__, Uri));
Status = EdkIIRedfishResourceConfigCheck (&SchemaInfo, Uri, NULL);
Expand Down
37 changes: 27 additions & 10 deletions RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ RedfishResourceConsumeResource (
// Check and see if "@Redfish.Settings" exist or not.
//
ZeroMem (&PendingSettingResponse, sizeof (REDFISH_RESPONSE));
Status = GetPendingSettings (
Private->RedfishService,
Response.Payload,
&PendingSettingResponse,
&PendingSettingUri
);
PendingSettingUri = NULL;
Status = GetPendingSettings (
Private->RedfishService,
Response.Payload,
&PendingSettingResponse,
&PendingSettingUri
);
if (!EFI_ERROR (Status)) {
DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", __func__, PendingSettingUri));
SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
Expand All @@ -151,8 +152,12 @@ RedfishResourceConsumeResource (
//
// Find etag in HTTP response header
//
Etag = NULL;
GetHttpResponseEtag (ExpectedResponse, &Etag);
Etag = NULL;
Status = GetHttpResponseEtag (ExpectedResponse, &Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n", __func__, Private->Uri, Status));
Expand All @@ -174,6 +179,10 @@ RedfishResourceConsumeResource (
FreePool (Etag);
}

if (PendingSettingUri != NULL) {
FreePool (PendingSettingUri);
}

return Status;
}

Expand Down Expand Up @@ -327,8 +336,12 @@ RedfishResourceCheck (
//
// Find etag in HTTP response header
//
Etag = NULL;
GetHttpResponseEtag (&Response, &Etag);
Etag = NULL;
Status = GetHttpResponseEtag (&Response, &Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Status = RedfishCheckResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to check resource from: %s: %r\n", __func__, Uri, Status));
Expand All @@ -337,6 +350,10 @@ RedfishResourceCheck (
//
// Release resource
//
if (Etag != NULL) {
FreePool (Etag);
}

RedfishHttpFreeResponse (&Response);
Private->Payload = NULL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ HandleResource (

//
// Check and see if target property exist or not even when collection member exists.
// If not, we sill do provision.
// If not, we still do provision.
//
DEBUG ((REDFISH_DEBUG_TRACE, "%a Check for %s\n", __func__, Uri));
Status = EdkIIRedfishResourceConfigCheck (&SchemaInfo, Uri, NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,7 @@ RedfishFeatureGetUnifiedArrayTypeConfigureLang (

/**
Find "ETag" from either HTTP header or Redfish response.
It's caller's responsibility to release Etag by calling FreePool().
@param[in] Response HTTP response
@param[out] Etag String buffer to return ETag
Expand Down Expand Up @@ -1814,6 +1815,7 @@ GetHttpResponseEtag (

/**
Find "Location" from either HTTP header or Redfish response.
It's caller's responsibility to release Location by calling FreePool().
@param[in] Response HTTP response
@param[out] Location String buffer to return Location
Expand Down

0 comments on commit e6b9610

Please sign in to comment.