Skip to content

Commit

Permalink
RedfishClientPkg: fix memory leak in ConverterLib
Browse files Browse the repository at this point in the history
The memory returned by json_dumps() must be freed.

Signed-off-by: Mike Maslenkin <[email protected]>
Cc: Abner Chang <[email protected]>
Cc: Nickle Wang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
  • Loading branch information
ghbaccount committed Jan 26, 2024
1 parent f87ee07 commit 5945e23
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion RedfishClientPkg/ConverterLib/src/RedfishCsCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,19 @@ CreateCsJsonByNode (
if (TempChar != NULL) {
Status = allocateRecordCsMemory (Cs, sizeof (RedfishCS_Type_JSON_Data), (void **)&CsTypeJson);
if (Status != RedfishCS_status_success) {
free (TempChar);
return Status;
}

Status = allocateRecordCsMemory (Cs, (RedfishCS_int)strlen (TempChar) + 1, (void **)&DumpStr);
if (Status != RedfishCS_status_success) {
free (TempChar);
return Status;
}

strncpy (DumpStr, TempChar, strlen (TempChar) + 1);
free (TempChar);

InitializeLinkHead (&CsTypeJson->Header.LinkEntry);
CsTypeJson->Header.ResourceType = RedfishCS_Type_JSON;
CsTypeJson->Header.ThisUri = ParentUri;
Expand Down Expand Up @@ -1506,9 +1510,10 @@ RemoveUnchangeableProperties (
Status = RedfishCS_status_insufficient_memory;
} else {
memcpy (NewJsonBuffer, TempChar, strlen (TempChar) + 1);
free (TempChar);
Status = RedfishCS_status_success;
}

free (TempChar);
} else {
Status = RedfishCS_status_unknown_error;
}
Expand Down

0 comments on commit 5945e23

Please sign in to comment.