Fix memory leak (#457)
authorAndrew Au <andrewau@microsoft.com>
Tue, 3 Sep 2019 20:46:21 +0000 (13:46 -0700)
committerGitHub <noreply@github.com>
Tue, 3 Sep 2019 20:46:21 +0000 (13:46 -0700)
src/SOS/Strike/strike.cpp

index f14b8c4ef1968e1ab2c6d3be37cbba7bcbe77288..439fd5e922a2d52a337bcf2e67a8ae897b18cea1 100644 (file)
@@ -9313,7 +9313,7 @@ DECLARE_API(u)
             return Status;
         }
 
-        CLRDATA_IL_ADDRESS_MAP* map = nullptr;
+        ArrayHolder<CLRDATA_IL_ADDRESS_MAP> map(nullptr);
         ULONG32 mapCount = 0;
 
         if ((Status = pMethodInst->GetILAddressMap(mapCount, &mapCount, map)) != S_OK)
@@ -9321,7 +9321,12 @@ DECLARE_API(u)
             return Status;
         }
 
-        map = new CLRDATA_IL_ADDRESS_MAP[mapCount];
+        map = new NOTHROW CLRDATA_IL_ADDRESS_MAP[mapCount];
+        if (map == NULL)
+        {
+            ReportOOM();
+            return E_OUTOFMEMORY;
+        }
 
         if ((Status = pMethodInst->GetILAddressMap(mapCount, &mapCount, map)) != S_OK)
         {
@@ -9334,8 +9339,6 @@ DECLARE_API(u)
             // Decoded IL can be obtained through refactoring DumpIL code.
             ExtOut("%04x %p %p\n", map[i].ilOffset, map[i].startAddress, map[i].endAddress);
         }
-
-        delete[] map;
     }
 
     if (codeHeaderData.ColdRegionStart != NULL)