Skip to content

Commit

Permalink
SecurityPkg: Fix memory leak in ExtendMeasurement
Browse files Browse the repository at this point in the history
Signed-off-by: Wenxing Hou <[email protected]>
  • Loading branch information
Wenxing-hou authored and jyao1 committed Jan 26, 2024
1 parent 9681b4f commit 3a1b51c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions SecurityPkg/DeviceSecurity/SpdmSecurityLib/SpdmMeasurement.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ ExtendMeasurement (

SpdmContext = SpdmDeviceContext->SpdmContext;

EventLog = NULL;
ZeroMem (&Parameter, sizeof (Parameter));
Parameter.location = SpdmDataLocationConnection;
DataSize = sizeof (MeasurementHashAlgo);
Expand Down Expand Up @@ -345,7 +346,8 @@ ExtendMeasurement (
Status = CreateDeviceMeasurementContext (SpdmDeviceContext, DeviceContext, DeviceContextSize);
if (Status != EFI_SUCCESS) {
SecurityState->MeasurementState = EDKII_DEVICE_SECURITY_STATE_ERROR_DEVICE_ERROR;
return EFI_DEVICE_ERROR;
Status = EFI_DEVICE_ERROR;
goto Exit;
}
}

Expand Down Expand Up @@ -399,7 +401,8 @@ ExtendMeasurement (
Status = CreateDeviceMeasurementContext (SpdmDeviceContext, DeviceContext, DeviceContextSize);
if (Status != EFI_SUCCESS) {
SecurityState->MeasurementState = EDKII_DEVICE_SECURITY_STATE_ERROR_DEVICE_ERROR;
return EFI_DEVICE_ERROR;
Status = EFI_DEVICE_ERROR;
goto Exit;
}
}

Expand All @@ -416,7 +419,7 @@ ExtendMeasurement (
}

DEBUG ((DEBUG_INFO, "TpmMeasureAndLogData (Measurement) - %r\n", Status));
return Status;
goto Exit;
default:
SecurityState->MeasurementState = EDKII_DEVICE_SECURITY_STATE_ERROR_UEFI_UNSUPPORTED;
return EFI_UNSUPPORTED;
Expand Down Expand Up @@ -475,6 +478,10 @@ ExtendMeasurement (

DEBUG ((DEBUG_INFO, "TpmMeasureAndLogData (Dynamic) - %r\n", Status));
}
Exit:
if (EventLog != NULL) {
FreePool(EventLog);
}

return Status;
}
Expand Down

0 comments on commit 3a1b51c

Please sign in to comment.