← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1741778-statistics_window_leaks into lp:widelands

 

Jukka Pakarinen has proposed merging lp:~widelands-dev/widelands/bug-1741778-statistics_window_leaks into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1741778 in widelands: "Plot area of Statistics has memory leak"
  https://bugs.launchpad.net/widelands/+bug/1741778

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1741778-statistics_window_leaks/+merge/335897

The changes in the branch fix the memory leaks reported in the bug 1741778. 

So, the problem is that WuiPlotArea allocates memory but doesn't release it. Memory leak happens when player leaves from a game. The leak is not fatal, but it should be fixed. The fix isn't the most stylish one but it does the work.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1741778-statistics_window_leaks into lp:widelands.
=== modified file 'src/wui/plot_area.cc'
--- src/wui/plot_area.cc	2017-11-12 13:34:46 +0000
+++ src/wui/plot_area.cc	2018-01-09 18:46:15 +0000
@@ -473,7 +473,7 @@
 	//  plot the pixels
 	for (uint32_t plot = 0; plot < plotdata_.size(); ++plot) {
 		if (plotdata_[plot].showplot) {
-			draw_plot_line(dst, (plotmode_ == Plotmode::kRelative) ? plotdata_[plot].relative_data :
+			draw_plot_line(dst, (plotmode_ == Plotmode::kRelative) ? plotdata_[plot].relative_data.get() :
 			                                                         plotdata_[plot].absolute_data,
 			               highest_scale, sub_, plotdata_[plot].plotcolor, yoffset);
 		}
@@ -537,8 +537,7 @@
 		plotdata_.resize(id + 1);
 
 	plotdata_[id].absolute_data = data;
-	plotdata_[id].relative_data =
-	   new std::vector<uint32_t>();  // Will be filled in the update() function.
+	plotdata_[id].relative_data.reset(new std::vector<uint32_t>());  // Will be filled in the update() function.
 	plotdata_[id].showplot = false;
 	plotdata_[id].plotcolor = color;
 

=== modified file 'src/wui/plot_area.h'
--- src/wui/plot_area.h	2017-05-04 04:37:16 +0000
+++ src/wui/plot_area.h	2018-01-09 18:46:15 +0000
@@ -21,6 +21,7 @@
 #define WL_WUI_PLOT_AREA_H
 
 #include <vector>
+#include <memory>
 
 #include <boost/bind.hpp>
 
@@ -116,7 +117,7 @@
 
 	struct PlotData {
 		const std::vector<uint32_t>* absolute_data;  // The absolute dataset
-		std::vector<uint32_t>* relative_data;        // The relative dataset
+		std::unique_ptr<std::vector<uint32_t> > relative_data;        // The relative dataset
 		bool showplot;
 		RGBColor plotcolor;
 	};


Follow ups