Browse Source

fix ASAN detected leaks and heap-use-after-free error

Mircea TheHonestCTO 1 month ago
parent
commit
c55187d664

+ 3 - 1
launcher/aboutProject/aboutproject_moc.cpp

@@ -33,7 +33,7 @@ void AboutProjectView::hideAndStretchWidget(QGridLayout * layout, QWidget * toHi
 
 AboutProjectView::AboutProjectView(QWidget * parent)
 	: QWidget(parent)
-	, ui(new Ui::AboutProjectView)
+	, ui(std::make_unique<Ui::AboutProjectView>())
 {
 	ui->setupUi(this);
 
@@ -56,6 +56,8 @@ AboutProjectView::AboutProjectView(QWidget * parent)
 #endif
 }
 
+AboutProjectView::~AboutProjectView() = default;
+
 void AboutProjectView::changeEvent(QEvent *event)
 {
 	if(event->type() == QEvent::LanguageChange)

+ 2 - 1
launcher/aboutProject/aboutproject_moc.h

@@ -28,6 +28,7 @@ class AboutProjectView : public QWidget
 
 public:
 	explicit AboutProjectView(QWidget * parent = nullptr);
+	~AboutProjectView() override;
 
 private slots:
 	void on_updatesButton_clicked();
@@ -49,5 +50,5 @@ private slots:
 	void on_openConfigDir_clicked();
 
 private:
-	Ui::AboutProjectView * ui;
+	std::unique_ptr<Ui::AboutProjectView> ui;
 };

+ 3 - 1
launcher/firstLaunch/firstlaunch_moc.cpp

@@ -41,7 +41,7 @@ extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_heroesDataUpda
 
 FirstLaunchView::FirstLaunchView(QWidget * parent)
 	: QWidget(parent)
-	, ui(new Ui::FirstLaunchView)
+	, ui(std::make_unique<Ui::FirstLaunchView>())
 {
 	ui->setupUi(this);
 
@@ -65,6 +65,8 @@ FirstLaunchView::FirstLaunchView(QWidget * parent)
 #endif
 }
 
+FirstLaunchView::~FirstLaunchView() = default;
+
 void FirstLaunchView::on_buttonTabLanguage_clicked()
 {
 	activateTabLanguage();

+ 2 - 1
launcher/firstLaunch/firstlaunch_moc.h

@@ -58,6 +58,7 @@ class FirstLaunchView : public QWidget
 
 public:
 	explicit FirstLaunchView(QWidget * parent = nullptr);
+	~FirstLaunchView() override;
 
 	// Tab Heroes III Data
 	bool heroesDataUpdate();
@@ -89,5 +90,5 @@ private slots:
 	void on_pushButtonGithub_clicked();
 
 private:
-	Ui::FirstLaunchView * ui;
+	std::unique_ptr<Ui::FirstLaunchView> ui;
 };

+ 3 - 1
launcher/modManager/cdownloadmanager_moc.cpp

@@ -73,17 +73,19 @@ void CDownloadManager::downloadFinished(QNetworkReply * reply)
 	if(possibleRedirectUrl.isValid())
 	{
 		QString filename;
+		qint64 totalSize = 0;
 
 		for(int i = 0; i< currentDownloads.size(); ++i)
 		{
 			if(currentDownloads[i].file == file.file)
 			{
 				filename = currentDownloads[i].filename;
+				totalSize = currentDownloads[i].totalSize;
 				currentDownloads.removeAt(i);
 				break;
 			}
 		}
-		downloadFile(qurl, filename, file.totalSize);
+		downloadFile(qurl, filename, totalSize);
 		return;
 	}