ImageTool: Fix memory leaks

This commit is contained in:
Marvin Häuser 2023-06-12 17:46:45 +02:00 committed by MikhailKrichanov
parent d5eb795bc9
commit 31c0046cbe
2 changed files with 7 additions and 0 deletions

View File

@ -166,6 +166,7 @@ ToolImageEmit (
if (OutputFile == NULL) { if (OutputFile == NULL) {
DEBUG_RAISE (); DEBUG_RAISE ();
ToolImageDestruct (&ImageInfo);
return NULL; return NULL;
} }
@ -175,6 +176,7 @@ ToolImageEmit (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
assert (false); assert (false);
FreePool (OutputFile);
return NULL; return NULL;
} }

View File

@ -238,6 +238,7 @@ ToolContextConstructUefiImage (
Success = ScanUefiImageGetHeaderInfo (&Image->HeaderInfo, &Context); Success = ScanUefiImageGetHeaderInfo (&Image->HeaderInfo, &Context);
if (!Success) { if (!Success) {
fprintf (stderr, "ImageTool: Could not retrieve header info\n"); fprintf (stderr, "ImageTool: Could not retrieve header info\n");
ToolImageDestruct (Image);
FreeAlignedPages (Destination, DestinationPages); FreeAlignedPages (Destination, DestinationPages);
return RETURN_VOLUME_CORRUPTED; return RETURN_VOLUME_CORRUPTED;
} }
@ -245,6 +246,7 @@ ToolContextConstructUefiImage (
Success = ScanUefiImageGetSegmentInfo (&Image->SegmentInfo, &Context); Success = ScanUefiImageGetSegmentInfo (&Image->SegmentInfo, &Context);
if (!Success) { if (!Success) {
fprintf (stderr, "ImageTool: Could not retrieve segment info\n"); fprintf (stderr, "ImageTool: Could not retrieve segment info\n");
ToolImageDestruct (Image);
FreeAlignedPages (Destination, DestinationPages); FreeAlignedPages (Destination, DestinationPages);
return RETURN_VOLUME_CORRUPTED; return RETURN_VOLUME_CORRUPTED;
} }
@ -252,6 +254,7 @@ ToolContextConstructUefiImage (
Success = ScanUefiImageGetRelocInfo (&Image->RelocInfo, &Context); Success = ScanUefiImageGetRelocInfo (&Image->RelocInfo, &Context);
if (!Success) { if (!Success) {
fprintf (stderr, "ImageTool: Could not retrieve reloc info\n"); fprintf (stderr, "ImageTool: Could not retrieve reloc info\n");
ToolImageDestruct (Image);
FreeAlignedPages (Destination, DestinationPages); FreeAlignedPages (Destination, DestinationPages);
return RETURN_VOLUME_CORRUPTED; return RETURN_VOLUME_CORRUPTED;
} }
@ -259,6 +262,7 @@ ToolContextConstructUefiImage (
Success = ScanUefiImageGetHiiInfo (&Image->HiiInfo, &Context); Success = ScanUefiImageGetHiiInfo (&Image->HiiInfo, &Context);
if (!Success) { if (!Success) {
fprintf (stderr, "ImageTool: Could not retrieve HII info\n"); fprintf (stderr, "ImageTool: Could not retrieve HII info\n");
ToolImageDestruct (Image);
FreeAlignedPages (Destination, DestinationPages); FreeAlignedPages (Destination, DestinationPages);
return RETURN_VOLUME_CORRUPTED; return RETURN_VOLUME_CORRUPTED;
} }
@ -266,6 +270,7 @@ ToolContextConstructUefiImage (
Success = ScanUefiImageGetDebugInfo (&Image->DebugInfo, &Context); Success = ScanUefiImageGetDebugInfo (&Image->DebugInfo, &Context);
if (!Success) { if (!Success) {
fprintf (stderr, "ImageTool: Could not retrieve debug info\n"); fprintf (stderr, "ImageTool: Could not retrieve debug info\n");
ToolImageDestruct (Image);
FreeAlignedPages (Destination, DestinationPages); FreeAlignedPages (Destination, DestinationPages);
return RETURN_VOLUME_CORRUPTED; return RETURN_VOLUME_CORRUPTED;
} }