瀏覽代碼

UI: Protect GUID generation in mutex

GUID can be generated/retrieved by both the updater thread and the main
thread, so make sure it's guarded by a mutex.
jp9000 7 年之前
父節點
當前提交
ee513000dc
共有 1 個文件被更改,包括 28 次插入32 次删除
  1. 28 32
      UI/win-update/win-update.cpp

+ 28 - 32
UI/win-update/win-update.cpp

@@ -482,6 +482,32 @@ void GenerateGUID(string &guid)
 	HashToString(junk, &guid[0]);
 }
 
+string GetProgramGUID()
+{
+	static mutex m;
+	lock_guard<mutex> lock(m);
+
+	/* NOTE: this is an arbitrary random number that we use to count the
+	 * number of unique OBS installations and is not associated with any
+	 * kind of identifiable information */
+	const char *pguid = config_get_string(GetGlobalConfig(),
+			"General", "InstallGUID");
+	string guid;
+	if (pguid)
+		guid = pguid;
+
+	if (guid.empty()) {
+		GenerateGUID(guid);
+
+		if (!guid.empty())
+			config_set_string(GetGlobalConfig(),
+					"General", "InstallGUID",
+					guid.c_str());
+	}
+
+	return guid;
+}
+
 void AutoUpdateThread::infoMsg(const QString &title, const QString &text)
 {
 	OBSMessageBox::information(App()->GetMainWindow(), title, text);
@@ -609,24 +635,7 @@ try {
 	/* ----------------------------------- *
 	 * get current install GUID            */
 
-	/* NOTE: this is an arbitrary random number that we use to count the
-	 * number of unique OBS installations and is not associated with any
-	 * kind of identifiable information */
-	const char *pguid = config_get_string(GetGlobalConfig(),
-			"General", "InstallGUID");
-	string guid;
-	if (pguid)
-		guid = pguid;
-
-	if (guid.empty()) {
-		GenerateGUID(guid);
-
-		if (!guid.empty())
-			config_set_string(GetGlobalConfig(),
-					"General", "InstallGUID",
-					guid.c_str());
-	}
-
+	string guid = GetProgramGUID();
 	if (!guid.empty()) {
 		string header = "X-OBS2-GUID: ";
 		header += guid;
@@ -829,20 +838,7 @@ try {
 	/* ----------------------------------- *
 	 * get current install GUID            */
 
-	const char *pguid = config_get_string(GetGlobalConfig(),
-			"General", "InstallGUID");
-	string guid;
-	if (pguid)
-		guid = pguid;
-
-	if (guid.empty()) {
-		GenerateGUID(guid);
-
-		if (!guid.empty())
-			config_set_string(GetGlobalConfig(),
-					"General", "InstallGUID",
-					guid.c_str());
-	}
+	string guid = GetProgramGUID();
 
 	if (!guid.empty()) {
 		string header = "X-OBS2-GUID: ";