kernelshark: Fix potential memory leak in KsGLWidget
In KsGLWidget::_newCPUGraph() and in KsGLWidget::_newTaskGraph()
allocate KsPlot::Graph after getting data stream successfully.
Also remove unused "name" local variable in both functions.
Signed-off-by: Benjamin ROBIN <dev@benjarobin.fr>
Signed-off-by: Yordan Karadzhov <y.karadz@gmail.com>
diff --git a/src/KsGLWidget.cpp b/src/KsGLWidget.cpp
index 87f4b20..eda705e 100644
--- a/src/KsGLWidget.cpp
+++ b/src/KsGLWidget.cpp
@@ -793,13 +793,8 @@
KsPlot::Graph *KsGLWidget::_newCPUGraph(int sd, int cpu)
{
- QString name;
- /* The CPU graph needs to know only the colors of the tasks. */
- KsPlot::Graph *graph = new KsPlot::Graph(_model.histo(),
- &_pidColors,
- &_pidColors);
-
- kshark_context *kshark_ctx(nullptr);
+ KsPlot::Graph *graph = nullptr;
+ kshark_context *kshark_ctx = nullptr;
kshark_data_stream *stream;
kshark_entry_collection *col;
@@ -810,6 +805,8 @@
if (!stream)
return nullptr;
+ /* The CPU graph needs to know only the colors of the tasks. */
+ graph = new KsPlot::Graph(_model.histo(), &_pidColors, &_pidColors);
graph->setIdleSuppressed(true, stream->idle_pid);
graph->setHeight(KS_GRAPH_HEIGHT);
graph->setLabelText(KsUtils::cpuPlotName(cpu).toStdString());
@@ -826,15 +823,8 @@
KsPlot::Graph *KsGLWidget::_newTaskGraph(int sd, int pid)
{
- QString name;
- /*
- * The Task graph needs to know the colors of the tasks and the colors
- * of the CPUs.
- */
- KsPlot::Graph *graph = new KsPlot::Graph(_model.histo(),
- &_pidColors,
- &_cpuColors);
- kshark_context *kshark_ctx(nullptr);
+ KsPlot::Graph *graph = nullptr;
+ kshark_context *kshark_ctx = nullptr;
kshark_entry_collection *col;
kshark_data_stream *stream;
@@ -845,6 +835,9 @@
if (!stream)
return nullptr;
+ /* The Task graph needs to know the colors of the tasks and the colors
+ * of the CPUs */
+ graph = new KsPlot::Graph(_model.histo(), &_pidColors, &_cpuColors);
graph->setHeight(KS_GRAPH_HEIGHT);
graph->setLabelText(KsUtils::taskPlotName(sd, pid).toStdString());