From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E10B881DA4 for ; Thu, 3 Nov 2016 00:23:59 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 03 Nov 2016 00:24:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,585,1473145200"; d="scan'208";a="897185220" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.34]) by orsmga003.jf.intel.com with ESMTP; 03 Nov 2016 00:24:00 -0700 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Liming Gao , Yonghong Zhu Date: Thu, 3 Nov 2016 15:22:42 +0800 Message-Id: <1478157783-9368-33-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1478157783-9368-1-git-send-email-hao.a.wu@intel.com> References: <1478157783-9368-1-git-send-email-hao.a.wu@intel.com> Subject: [PATCH v2 32/53] BaseTools/GenFv: Fix potential memory leak X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Nov 2016 07:24:00 -0000 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- BaseTools/Source/C/GenFv/GenFvInternalLib.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c index d16b33e..bf6b40c 100644 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c @@ -1220,6 +1220,7 @@ Returns: if (CompareGuid ((EFI_GUID *) FileBuffer, &mFileGuidArray [Index1]) == 0) { Error (NULL, 0, 2000, "Invalid parameter", "the %dth file and %uth file have the same file GUID.", (unsigned) Index1 + 1, (unsigned) Index + 1); PrintGuid ((EFI_GUID *) FileBuffer); + free (FileBuffer); return EFI_INVALID_PARAMETER; } } @@ -2626,7 +2627,7 @@ Returns: // Status = CalculateFvSize (&mFvDataInfo); if (EFI_ERROR (Status)) { - return Status; + goto Finish; } VerboseMsg ("the generated FV image size is %u bytes", (unsigned) mFvDataInfo.Size); @@ -2640,7 +2641,8 @@ Returns: // FvBufferHeader = malloc (FvImageSize + sizeof (UINT64)); if (FvBufferHeader == NULL) { - return EFI_OUT_OF_RESOURCES; + Status = EFI_OUT_OF_RESOURCES; + goto Finish; } FvImage = (UINT8 *) (((UINTN) FvBufferHeader + 7) & ~7); @@ -2732,7 +2734,8 @@ Returns: FvMapFile = fopen (LongFilePath (FvMapName), "w"); if (FvMapFile == NULL) { Error (NULL, 0, 0001, "Error opening file", FvMapName); - return EFI_ABORTED; + Status = EFI_ABORTED; + goto Finish; } // @@ -2741,7 +2744,8 @@ Returns: FvReportFile = fopen (LongFilePath (FvReportName), "w"); if (FvReportFile == NULL) { Error (NULL, 0, 0001, "Error opening file", FvReportName); - return EFI_ABORTED; + Status = EFI_ABORTED; + goto Finish; } // // record FV size information into FvMap file. @@ -4259,6 +4263,7 @@ Returns: fwrite (CapBuffer, 1, CapSize, fpout); fclose (fpout); + free (CapBuffer); VerboseMsg ("The size of the generated capsule image is %u bytes", (unsigned) CapSize); -- 1.9.5.msysgit.0