(svn r13126) -Fix (r13022) [FS#2009, FS#2010]: driver list should be dynamically allocated as static uninitialistion order is undetermined. The list is freed when the latest driver is removed.
authorglx
Fri, 16 May 2008 21:32:10 +0000
changeset 10582 412f937a27d9
parent 10581 7255fef8c069
child 10583 edc21c3e1386
(svn r13126) -Fix (r13022) [FS#2009, FS#2010]: driver list should be dynamically allocated as static uninitialistion order is undetermined. The list is freed when the latest driver is removed.
src/driver.h
--- a/src/driver.h	Fri May 16 21:04:49 2008 +0000
+++ b/src/driver.h	Fri May 16 21:32:10 2008 +0000
@@ -43,7 +43,7 @@
 
 	static Drivers &GetDrivers()
 	{
-		static Drivers s_drivers;
+		static Drivers &s_drivers = *new Drivers();
 		return s_drivers;
 	}
 
@@ -71,7 +71,14 @@
 	 */
 	virtual ~DriverFactoryBase() {
 		if (this->name == NULL) return;
-		GetDrivers().erase(this->name);
+
+		/* Prefix the name with driver type to make it unique */
+		char buf[32];
+		strecpy(buf, GetDriverTypeName(type), lastof(buf));
+		strecpy(buf + 5, this->name, lastof(buf));
+
+		GetDrivers().erase(buf);
+		if (GetDrivers().empty()) delete &GetDrivers();
 		free(this->name);
 	}