Add a destructor for MethodCallSummarizer (dotnet/coreclr#24088)
authorOmair Majid <omajid@redhat.com>
Tue, 29 Oct 2019 00:13:11 +0000 (20:13 -0400)
committerSergey Andreenko <seandree@microsoft.com>
Tue, 29 Oct 2019 00:13:11 +0000 (17:13 -0700)
The destructor cleans up resources allocated by MethodCallSummarizer
during its normal lifetime.

Commit migrated from https://github.com/dotnet/coreclr/commit/caaed1b78c3c20dc17e39e2986712264149ae923

src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.cpp
src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/methodcallsummarizer.h

index 3f41973d168088b99204ab510f80921e375120ac..ce8d98aa499fcfe0e297bf4a78eecc6f3d8cf3d8 100644 (file)
@@ -20,6 +20,17 @@ MethodCallSummarizer::MethodCallSummarizer(WCHAR* logPath)
     dataFileName = GetResultFileName(logPath, fileName, extension);
 }
 
+MethodCallSummarizer::~MethodCallSummarizer()
+{
+    delete [] dataFileName;
+    delete [] counts;
+    for (int i = 0; i < numNames; i++)
+    {
+        delete [] names[i];
+    }
+    delete [] names;
+}
+
 // lots of ways will be faster.. this happens to be decently simple and good enough for the task at hand and nicely
 // sorts the output. in this approach the most commonly added items are at the top of the list... 60% landed in the
 // first
@@ -54,7 +65,7 @@ void MethodCallSummarizer::AddCall(const char* name)
     if (tnames != nullptr)
     {
         memcpy(names, tnames, numNames * sizeof(char*));
-        delete tnames;
+        delete [] tnames;
     }
 
     size_t tlen     = strlen(name);
@@ -65,7 +76,7 @@ void MethodCallSummarizer::AddCall(const char* name)
     if (tcounts != nullptr)
     {
         memcpy(counts, tcounts, numNames * sizeof(unsigned int));
-        delete tcounts;
+        delete [] tcounts;
     }
     counts[numNames] = 1;
 
index c45b631e760bc1b5a78e46a086016de751aaf91b..94bbf2d312297316fa53cc5970c56accc5ab7d44 100644 (file)
@@ -10,6 +10,7 @@ class MethodCallSummarizer
 {
 public:
     MethodCallSummarizer(WCHAR* name);
+    ~MethodCallSummarizer();
     void AddCall(const char* name);
     void SaveTextFile();
 
@@ -20,4 +21,4 @@ private:
     WCHAR*        dataFileName;
 };
 
-#endif
\ No newline at end of file
+#endif