diff mbox series

[08/12] kernel-shark: Fix memory leak in KsPlotget::getTaskColorTable()

Message ID 20190314151012.905-9-ykaradzhov@vmware.com (mailing list archive)
State Accepted
Headers show
Series Various modifications and fixes toward KS 1.0 | expand

Commit Message

Yordan Karadzhov March 14, 2019, 3:10 p.m. UTC
The std::vector constructor used here makes a copy of the data, so
the memory used by the original array has to be freed.

This is a major leak because getTaskColorTable() gets called every
time when we redraw the plots.

BTW calling getTaskColorTable() every time when we redraw makes
no sense. This will be fixed in the following patch.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/src/KsPlotTools.cpp | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/kernel-shark/src/KsPlotTools.cpp b/kernel-shark/src/KsPlotTools.cpp
index d07f414..2b16a51 100644
--- a/kernel-shark/src/KsPlotTools.cpp
+++ b/kernel-shark/src/KsPlotTools.cpp
@@ -122,6 +122,8 @@  ColorTable getTaskColorTable()
 	std::vector<int> temp_pids(pids, pids + nTasks);
 	std::sort(temp_pids.begin(), temp_pids.end());
 
+	free(pids);
+
 	if (temp_pids[i] == 0) {
 		/* The "Idle" process (pid = 0) will be plotted in black. */
 		colors[i++] = {};