diff mbox series

[07/34] kernelshark: Fix potential memory leak in KsGLWidget

Message ID 20240114171723.14092-8-dev@benjarobin.fr (mailing list archive)
State Accepted
Commit 4babc5f2f96b6756ae75595365dd5956373c9909
Headers show
Series Fix kernelshark issues introduced by the migration to Qt6 | expand

Commit Message

Benjamin ROBIN Jan. 14, 2024, 5:16 p.m. UTC
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>
---
 src/KsGLWidget.cpp | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/src/KsGLWidget.cpp b/src/KsGLWidget.cpp
index 0a44e77..23485d2 100644
--- a/src/KsGLWidget.cpp
+++ b/src/KsGLWidget.cpp
@@ -794,13 +794,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;
 
@@ -811,6 +806,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());
@@ -827,15 +824,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;
 
@@ -846,6 +836,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());