← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3080: Fix a crash when closing the download queue

 

------------------------------------------------------------
revno: 3080
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2012-10-19 12:40:17 +0200
message:
  Fix a crash when closing the download queue
modified:
  changelog.txt
  win32/QueueFrame.cpp
  win32/TypedTree.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2012-10-11 16:37:31 +0000
+++ changelog.txt	2012-10-19 10:40:17 +0000
@@ -4,6 +4,7 @@
 * Fix incorrect user lists when DC++ is under heavy load (poy)
 * Plug resource leaks (poy)
 * [L#411484] [ADC] Fix BLOM when h > 32 (thanks yorhel)
+* [L#198416] Fix a crash when closing the download queue (poy)
 
 -- 0.801 2012-09-29 --
 * [L#1029629] Prevent crashes on heavy use by updating Boost.Atomic

=== modified file 'win32/QueueFrame.cpp'
--- win32/QueueFrame.cpp	2012-10-11 16:17:05 +0000
+++ win32/QueueFrame.cpp	2012-10-19 10:40:17 +0000
@@ -278,9 +278,11 @@
 
 	files->clear();
 
+	curDir = getSelectedDir();
+
 	decltype(directories.equal_range(string())) i;
 	if(SETTING(QUEUEFRAME_SHOW_TREE)) {
-		i = directories.equal_range(getSelectedDir());
+		i = directories.equal_range(curDir);
 	} else {
 		i.first = directories.begin();
 		i.second = directories.end();
@@ -294,8 +296,6 @@
 
 	files->resort();
 
-	curDir = getSelectedDir();
-
 	filesDirty = true;
 	updateStatus();
 }

=== modified file 'win32/TypedTree.h'
--- win32/TypedTree.h	2012-07-11 17:13:42 +0000
+++ win32/TypedTree.h	2012-10-19 10:40:17 +0000
@@ -19,6 +19,9 @@
 #ifndef DCPLUSPLUS_WIN32_TYPED_TREE_H
 #define DCPLUSPLUS_WIN32_TYPED_TREE_H
 
+#include <memory>
+#include <vector>
+
 #include "forward.h"
 #include "WinUtil.h"
 
@@ -95,11 +98,20 @@
 
 	void clear() {
 		if(managed) {
+			/* go through every node to gather the data to delete. don't delete it right away
+			because the clear() call might lead to tree-view notifications which will need the data
+			to still be available. */
+			std::vector<std::unique_ptr<ContentType>> deleter;
+			deleter.reserve(this->size());
+
 			auto item = this->getRoot();
 			while(item) {
-				this->clear(item);
+				this->clear(item, deleter);
 				item = this->getNextSibling(item);
 			}
+
+			this->BaseType::clear();
+			return;
 		}
 
 		this->BaseType::clear();
@@ -127,13 +139,14 @@
 		}
 	}
 
-	void clear(HTREEITEM item) {
+	template<typename Deleter>
+	void clear(HTREEITEM item, Deleter& deleter) {
 		auto next = this->getChild(item);
 		while(next) {
-			clear(next);
+			clear(next, deleter);
 			next = this->getNextSibling(next);
 		}
-		delete this->getData(item);
+		deleter.emplace_back(this->getData(item));
 	}
 };