Skip to content

Commit

Permalink
kernelshark: Fix potential memory leak in KsGLWidget
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Yordan Karadzhov <[email protected]>
  • Loading branch information
benjarobin authored and yordan-karadzhov committed Jan 20, 2024
1 parent 5714179 commit 4babc5f
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/KsGLWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
Expand All @@ -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;

Expand All @@ -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());

Expand Down

0 comments on commit 4babc5f

Please sign in to comment.