Skip to content

Commit

Permalink
RedfishClientPkg: RedfishFeatureUtilityLib: fix memory leaks
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Maslenkin <[email protected]>
  • Loading branch information
ghbaccount committed Sep 27, 2023
1 parent d8bfe0f commit d456b6b
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ ApplyFeatureSettingsVagueType (
Status = UnicodeStrToAsciiStrS (ConfigureLang, ConfigureLangAscii, StrLen (ConfigureLang) + 1);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, Convert the configureLang of vague key of %a.%a %s failed: %r\n", __func__, Schema, Version, ConfigureLang, Status));
FreePool (ConfigureLangAscii);
return Status;
}

Expand Down Expand Up @@ -803,6 +804,7 @@ ApplyFeatureSettingsStringArrayType (
RedfishValue.Value.StringArray[Index] = AllocateCopyPool (AsciiStrSize (Buffer->ArrayValue), Buffer->ArrayValue);
if (RedfishValue.Value.StringArray[Index] == NULL) {
ASSERT (FALSE);
FreePool (RedfishValue.Value.StringArray);
return EFI_OUT_OF_RESOURCES;
}

Expand Down Expand Up @@ -924,6 +926,11 @@ ApplyFeatureSettingsNumericArrayType (
}
}

for (Index = 0; Index < RedfishValue.ArrayCount; Index++) {
FreePool (RedfishValue.Value.StringArray[Index]);
}
FreePool (RedfishValue.Value.StringArray);

return Status;
}

Expand Down Expand Up @@ -1972,6 +1979,7 @@ RedfishGetUri (
//
if (*Target == '\0') {
DEBUG ((DEBUG_ERROR, "%a, invalid format: %s\n", __func__, ConfigLang));
FreePool (ResultStr);
return NULL;
}

Expand All @@ -1983,6 +1991,7 @@ RedfishGetUri (
TempStrSize = (ConfigLangLen - RemainingLen + 1) * sizeof (CHAR16);
TempStr = AllocateCopyPool (TempStrSize, Head);
if (TempStr == NULL) {
FreePool (ResultStr);
return NULL;
}

Expand All @@ -1996,6 +2005,8 @@ RedfishGetUri (
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, Can not find: %s\n", __func__, TempStr));
FreePool (ResultStr);
FreePool (TempStr);
return NULL;
}

Expand Down Expand Up @@ -2102,10 +2113,14 @@ GetConfigureLang (

Status = AsciiStrToUnicodeStrS (Uri, UnicodeUri, StringSize);
if (EFI_ERROR (Status)) {
FreePool (UnicodeUri);
return NULL;
}

ConfigLang = RedfishGetConfigLanguage (UnicodeUri);

FreePool (UnicodeUri);

if (ConfigLang == NULL) {
return NULL;
}
Expand All @@ -2117,11 +2132,14 @@ GetConfigureLang (
StringSize = StrSize (ConfigLang) + ((AsciiStrLen (PropertyName) + 1) * sizeof (CHAR16));
ResultStr = AllocatePool (StringSize);
if (ResultStr == NULL) {
FreePool (ConfigLang);
return NULL;
}

UnicodeSPrint (ResultStr, StringSize, L"%s/%a", ConfigLang, PropertyName);

FreePool (ConfigLang);

return ResultStr;
}

Expand Down Expand Up @@ -2296,9 +2314,12 @@ GetPropertyStringValue (
Status = RedfishPlatformConfigGetValue (Schema, Version, ConfigureLangBuffer, &RedfishValue);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a query current setting for %s failed: %r\n", __func__, Schema, Version, ConfigureLangBuffer, Status));
FreePool (ConfigureLangBuffer);
return NULL;
}

FreePool (ConfigureLangBuffer);

if (RedfishValue.Type != RedfishValueTypeString) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string type\n", __func__, Schema, Version, ConfigureLang));
return NULL;
Expand Down Expand Up @@ -2354,9 +2375,12 @@ GetPropertyNumericValue (
Status = RedfishPlatformConfigGetValue (Schema, Version, ConfigureLangBuffer, &RedfishValue);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a query current setting for %s failed: %r\n", __func__, Schema, Version, ConfigureLangBuffer, Status));
FreePool (ConfigureLangBuffer);
return NULL;
}

FreePool (ConfigureLangBuffer);

if (RedfishValue.Type != RedfishValueTypeInteger) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not numeric type\n", __func__, Schema, Version, ConfigureLang));
return NULL;
Expand Down Expand Up @@ -2416,9 +2440,12 @@ GetPropertyBooleanValue (
Status = RedfishPlatformConfigGetValue (Schema, Version, ConfigureLangBuffer, &RedfishValue);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a query current setting for %s failed: %r\n", __func__, Schema, Version, ConfigureLangBuffer, Status));
FreePool (ConfigureLangBuffer);
return NULL;
}

FreePool (ConfigureLangBuffer);

if (RedfishValue.Type != RedfishValueTypeBoolean) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not boolean type\n", __func__, Schema, Version, ConfigureLang));
return NULL;
Expand Down Expand Up @@ -2517,9 +2544,12 @@ GetPropertyStringArrayValue (
Status = RedfishPlatformConfigGetValue (Schema, Version, ConfigureLangBuffer, &RedfishValue);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a query current setting for %s failed: %r\n", __func__, Schema, Version, ConfigureLangBuffer, Status));
FreePool (ConfigureLangBuffer);
return NULL;
}

FreePool (ConfigureLangBuffer);

if (RedfishValue.Type != RedfishValueTypeStringArray) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", __func__, Schema, Version, ConfigureLang));
return NULL;
Expand Down Expand Up @@ -2588,9 +2618,12 @@ GetPropertyNumericArrayValue (
Status = RedfishPlatformConfigGetValue (Schema, Version, ConfigureLangBuffer, &RedfishValue);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a query current setting for %s failed: %r\n", __func__, Schema, Version, ConfigureLangBuffer, Status));
FreePool (ConfigureLangBuffer);
return NULL;
}

FreePool (ConfigureLangBuffer);

if (RedfishValue.Type != RedfishValueTypeIntegerArray) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", __func__, Schema, Version, ConfigureLang));
return NULL;
Expand Down Expand Up @@ -2659,9 +2692,12 @@ GetPropertyBooleanArrayValue (
Status = RedfishPlatformConfigGetValue (Schema, Version, ConfigureLangBuffer, &RedfishValue);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a query current setting for %s failed: %r\n", __func__, Schema, Version, ConfigureLangBuffer, Status));
FreePool (ConfigureLangBuffer);
return NULL;
}

FreePool (ConfigureLangBuffer);

if (RedfishValue.Type != RedfishValueTypeBooleanArray) {
DEBUG ((DEBUG_ERROR, "%a, %a.%a %s value is not string array type\n", __func__, Schema, Version, ConfigureLang));
return NULL;
Expand Down

0 comments on commit d456b6b

Please sign in to comment.