aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin ROBIN <dev@benjarobin.fr>2024-01-14 18:16:56 +0100
committerYordan Karadzhov <y.karadz@gmail.com>2024-01-20 21:07:47 +0200
commit4babc5f2f96b6756ae75595365dd5956373c9909 (patch)
tree8b466a6a37c7b41a1b898d2d89adf228ae841e57
parent5714179d3185df979896b95deb85aca332de4d65 (diff)
downloadkernel-shark-4babc5f2f96b6756ae75595365dd5956373c9909.tar.gz
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>
-rw-r--r--src/KsGLWidget.cpp25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/KsGLWidget.cpp b/src/KsGLWidget.cpp
index 87f4b20c..eda705e1 100644
--- a/src/KsGLWidget.cpp
+++ b/src/KsGLWidget.cpp
@@ -793,13 +793,8 @@ void KsGLWidget::_makePluginShapes()
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 @@ KsPlot::Graph *KsGLWidget::_newCPUGraph(int sd, int cpu)
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::_newCPUGraph(int sd, int cpu)
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 @@ KsPlot::Graph *KsGLWidget::_newTaskGraph(int sd, int pid)
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());