← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2443: Plug a resource leak with regard to tab icons

 

------------------------------------------------------------
revno: 2443
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2011-02-25 18:46:24 +0100
message:
  Plug a resource leak with regard to tab icons
modified:
  changelog.txt
  dwt/include/dwt/resources/Icon.h
  dwt/src/Icon.cpp
  dwt/src/widgets/TabView.cpp


--
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	2011-02-25 17:43:09 +0000
+++ changelog.txt	2011-02-25 17:46:24 +0000
@@ -15,6 +15,7 @@
 * Report the progress of file list searches in the status bar (poy)
 * Repurpose Ctrl+F to in-place searches in chat windows & file lists (poy)
 * Prevent endless redirection loops with some Coral servers (poy)
+* [L#590651] Plug a resource leak with regard to tab icons (poy)
 
 -- 0.781 2011-01-12 --
 * Add a dummy serial number to TLS certs to satisfy some parsers (poy)

=== modified file 'dwt/include/dwt/resources/Icon.h'
--- dwt/include/dwt/resources/Icon.h	2011-02-19 17:03:15 +0000
+++ dwt/include/dwt/resources/Icon.h	2011-02-25 17:46:24 +0000
@@ -69,7 +69,7 @@
 	  * @params size desired size, useful to pick up the correct image when the icon contains
 	  * multiple images. if 0, the system will figure out the size of the 1st image by itself.
 	  */
-	explicit Icon(unsigned resourceId, const Point& size = Point(0, 0));
+	explicit Icon(const unsigned resourceId, const Point& size = Point(0, 0));
 
 	/// RAII Constructor loading a icon from a file on disc
 	/** Note! <br>
@@ -86,9 +86,13 @@
 	*/
 	Point getSize() const;
 
+	bool operator==(const Icon& rhs) const;
+
 private:
 	friend class Handle<IconPolicy>;
 	typedef Handle<IconPolicy> ResourceType;
+
+	const unsigned resId; // store the resource id to facilitate the comparison in operator==
 };
 
 }

=== modified file 'dwt/src/Icon.cpp'
--- dwt/src/Icon.cpp	2011-01-02 17:12:02 +0000
+++ dwt/src/Icon.cpp	2011-02-25 17:46:24 +0000
@@ -40,23 +40,26 @@
 namespace dwt {
 
 Icon::Icon(HICON icon, bool own) :
-ResourceType(icon, own)
+ResourceType(icon, own),
+resId(0)
 {
 }
 
-Icon::Icon(unsigned resourceId, const Point& size) :
+Icon::Icon(const unsigned resourceId, const Point& size) :
 /*
 * we use ::LoadImage instead of ::LoadIcon in order to be able to pick up the correct image,
 * depending on the "size" argument. also, our call to ::LoadImage should use LR_SHARED to match
 * ::LoadIcon more closely, but we don't pass that flag since all our icons are managed and
 * destroyed by DWT.
 */
-ResourceType((HICON)::LoadImage(::GetModuleHandle(NULL), MAKEINTRESOURCE(resourceId), IMAGE_ICON, size.x, size.y, LR_DEFAULTCOLOR))
+ResourceType((HICON)::LoadImage(::GetModuleHandle(NULL), MAKEINTRESOURCE(resourceId), IMAGE_ICON, size.x, size.y, LR_DEFAULTCOLOR)),
+resId(resourceId)
 {
 }
 
 Icon::Icon(const tstring& filePath) :
-ResourceType((HICON)::LoadImage(::GetModuleHandle(NULL), filePath.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE))
+ResourceType((HICON)::LoadImage(::GetModuleHandle(NULL), filePath.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE)),
+resId(0)
 {
 }
 
@@ -72,4 +75,11 @@
 	return color.getSize();
 }
 
+bool Icon::operator==(const Icon& rhs) const {
+	if(resId && rhs.resId)
+		return resId == rhs.resId;
+
+	return HandleType(resId) == HandleType(rhs.resId);
+}
+
 }

=== modified file 'dwt/src/widgets/TabView.cpp'
--- dwt/src/widgets/TabView.cpp	2011-02-01 21:33:33 +0000
+++ dwt/src/widgets/TabView.cpp	2011-02-25 17:46:24 +0000
@@ -473,7 +473,7 @@
 	int image = -1;
 	if(icon) {
 		for(size_t i = 0; i < icons.size(); ++i) {
-			if(icon == icons[i]) {
+			if(*icon == *icons[i]) {
 				image = i;
 				break;
 			}