summarylogtreecommitdiffstats
path: root/fix_audio_cache.patch
blob: b744d119a5e84f1b0d193125a3c6e7f85d26772c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From 1c6999b33a1b66b46143266ba9f842a32e837484 Mon Sep 17 00:00:00 2001
From: Myaamori <myaamori1993@gmail.com>
Date: Thu, 21 May 2020 05:11:15 +0100
Subject: [PATCH] Fix mutation while iterating corrupting linked list in
 block_cache.h

---
 src/block_cache.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/block_cache.h b/src/block_cache.h
index f2ebfa261..4025dac11 100644
--- a/src/block_cache.h
+++ b/src/block_cache.h
@@ -91,7 +91,6 @@ class DataBlockCache {
 		size -= (ba.size() - std::count(ba.begin(), ba.end(), nullptr)) * factory.GetBlockSize();
 
 		ba.clear();
-		age.erase(mb.position);
 	}
 
 public:
@@ -150,8 +149,16 @@
 		}

 		// Remove old entries until we're under the max size
-		for (auto it = age.rbegin(); size > max_size && it != age.rend(); it++)
-			KillMacroBlock(**it);
+		auto it = age.end();
+		while (size > max_size) {
+			if (it == age.begin())
+				break;
+			it--;
+			KillMacroBlock(**it);
+		}
+
+		while (it != age.end())
+			it = age.erase(it);
 	}

 	/// @brief Obtain a data block from the cache