Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Add a destructor for MethodCallSummarizer (#24088)
Browse files Browse the repository at this point in the history
The destructor cleans up resources allocated by MethodCallSummarizer
during its normal lifetime.
  • Loading branch information
omajid authored and Sergey Andreenko committed Oct 29, 2019
1 parent 2773be5 commit caaed1b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MethodCallSummarizer
{
public:
MethodCallSummarizer(WCHAR* name);
~MethodCallSummarizer();
void AddCall(const char* name);
void SaveTextFile();

Expand All @@ -20,4 +21,4 @@ class MethodCallSummarizer
WCHAR* dataFileName;
};

#endif
#endif

0 comments on commit caaed1b

Please sign in to comment.