@@ -769,6 +769,7 @@ mirror_one_mok_variable(struct mok_state_variable *v,
769
769
EFI_STATUS efi_status = EFI_SUCCESS ;
770
770
uint8_t * FullData = NULL ;
771
771
size_t FullDataSize = 0 ;
772
+ bool allocated_full_data = false;
772
773
vendor_addend_category_t addend_category = VENDOR_ADDEND_NONE ;
773
774
uint8_t * p = NULL ;
774
775
uint32_t attrs = EFI_VARIABLE_BOOTSERVICE_ACCESS |
@@ -833,6 +834,7 @@ mirror_one_mok_variable(struct mok_state_variable *v,
833
834
if (efi_status != EFI_BUFFER_TOO_SMALL ) {
834
835
perror (L"Could not add built-in cert to %s: %r\n" ,
835
836
v -> name , efi_status );
837
+ goto err ;
836
838
return efi_status ;
837
839
}
838
840
FullDataSize += addend_esl_sz ;
@@ -917,6 +919,7 @@ mirror_one_mok_variable(struct mok_state_variable *v,
917
919
FullDataSize , v -> name );
918
920
return EFI_OUT_OF_RESOURCES ;
919
921
}
922
+ allocated_full_data = true;
920
923
p = FullData ;
921
924
}
922
925
}
@@ -946,7 +949,7 @@ mirror_one_mok_variable(struct mok_state_variable *v,
946
949
if (EFI_ERROR (efi_status )) {
947
950
perror (L"Could not add built-in cert to %s: %r\n" ,
948
951
v -> name , efi_status );
949
- return efi_status ;
952
+ goto err ;
950
953
}
951
954
p += addend_esl_sz ;
952
955
dprint (L"FullDataSize:%lu FullData:0x%llx p:0x%llx pos:%lld\n" ,
@@ -973,7 +976,7 @@ mirror_one_mok_variable(struct mok_state_variable *v,
973
976
if (EFI_ERROR (efi_status )) {
974
977
perror (L"Could not add built-in cert to %s: %r\n" ,
975
978
v -> name , efi_status );
976
- return efi_status ;
979
+ goto err ;
977
980
}
978
981
p += build_cert_esl_sz ;
979
982
dprint (L"FullDataSize:%lu FullData:0x%llx p:0x%llx pos:%lld\n" ,
@@ -1012,7 +1015,7 @@ mirror_one_mok_variable(struct mok_state_variable *v,
1012
1015
if (EFI_ERROR (efi_status )) {
1013
1016
perror (L"Failed to allocate %lu bytes for %s\n" ,
1014
1017
FullDataSize , v -> name );
1015
- return efi_status ;
1018
+ goto err ;
1016
1019
}
1017
1020
p = FullData + FullDataSize ;
1018
1021
dprint (L"FullDataSize:%lu FullData:0x%llx p:0x%llx pos:%lld\n" ,
@@ -1045,7 +1048,7 @@ mirror_one_mok_variable(struct mok_state_variable *v,
1045
1048
if (EFI_ERROR (efi_status )) {
1046
1049
dprint (L"tpm_measure_variable(\"%s\",%lu,0x%llx)->%r\n" ,
1047
1050
v -> name , FullDataSize , FullData , efi_status );
1048
- return efi_status ;
1051
+ goto err ;
1049
1052
}
1050
1053
}
1051
1054
@@ -1062,7 +1065,7 @@ mirror_one_mok_variable(struct mok_state_variable *v,
1062
1065
dprint (L"tpm_log_event(0x%llx, %lu, %lu, \"%s\")->%r\n" ,
1063
1066
FullData , FullDataSize , v -> pcr , v -> name ,
1064
1067
efi_status );
1065
- return efi_status ;
1068
+ goto err ;
1066
1069
}
1067
1070
}
1068
1071
@@ -1076,6 +1079,10 @@ mirror_one_mok_variable(struct mok_state_variable *v,
1076
1079
v -> data_size = FullDataSize ;
1077
1080
dprint (L"returning %r\n" , efi_status );
1078
1081
return efi_status ;
1082
+ err :
1083
+ if (FullData && allocated_full_data )
1084
+ FreePool (FullData );
1085
+ return efi_status ;
1079
1086
}
1080
1087
1081
1088
/*
0 commit comments