]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/VolInfo: Fix potential memory leak
authorHao Wu <hao.a.wu@intel.com>
Tue, 11 Oct 2016 07:27:55 +0000 (15:27 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 8 Nov 2016 08:37:52 +0000 (16:37 +0800)
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/C/VolInfo/VolInfo.c

index 5da658298e17aca8af7150ec0555d618e31707cd..312d33221b8c3f56174bab22a9f47f58150f166b 100644 (file)
@@ -258,6 +258,14 @@ Returns:
       continue;\r
     }\r
     if ((stricmp (argv[0], "--hash") == 0)) {\r
       continue;\r
     }\r
     if ((stricmp (argv[0], "--hash") == 0)) {\r
+      if (EnableHash == TRUE) {\r
+        //\r
+        // --hash already given in the option, ignore this one\r
+        //\r
+        argc --;\r
+        argv ++;\r
+        continue;\r
+      }\r
       EnableHash = TRUE;\r
       OpenSslCommand = "openssl";\r
       OpenSslEnv = getenv("OPENSSL_PATH");\r
       EnableHash = TRUE;\r
       OpenSslCommand = "openssl";\r
       OpenSslEnv = getenv("OPENSSL_PATH");\r
@@ -1784,8 +1792,14 @@ Returns:
         }\r
 \r
         ScratchBuffer       = malloc (ScratchSize);\r
         }\r
 \r
         ScratchBuffer       = malloc (ScratchSize);\r
+        if (ScratchBuffer == NULL) {\r
+          Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+          return EFI_OUT_OF_RESOURCES;\r
+        }\r
         UncompressedBuffer  = malloc (UncompressedLength);\r
         UncompressedBuffer  = malloc (UncompressedLength);\r
-        if ((ScratchBuffer == NULL) || (UncompressedBuffer == NULL)) {\r
+        if (UncompressedBuffer == NULL) {\r
+          free (ScratchBuffer);\r
+          Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
         Status = DecompressFunction (\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
         Status = DecompressFunction (\r