Skip to content

Commit 28f4c38

Browse files
committed
Fix a memory leak in header downloader's downloaded
The header downloader has two queues. The first one is the downloaded queue, and the second one is the "queued" queue. If a header is downloaded, downloader enqueues the header to the downloaded queue. When starting to import the header, the downloader removes the header from the downloaded queue and enqueues the header to the "queued" queue. When the importing is done, the downloader removes the header from the "queued" queue. However, if a header(let's call it A) is downloaded and is imported already, A is not removed from the downloaded queue forever. This commit removes A from the downloaded header.
1 parent 48a3b88 commit 28f4c38

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

sync/src/block/downloader/header.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ impl HeaderDownloader {
179179
pub fn mark_as_imported(&mut self, hashes: Vec<H256>) {
180180
for hash in hashes {
181181
self.queued.remove(&hash);
182+
self.downloaded.remove(&hash);
182183

183184
if self.best_hash == hash {
184185
self.pivot = Pivot {
@@ -188,6 +189,7 @@ impl HeaderDownloader {
188189
}
189190
}
190191
self.queued.shrink_to_fit();
192+
self.downloaded.shrink_to_fit();
191193
}
192194

193195
pub fn mark_as_queued(&mut self, hashes: Vec<H256>) {

0 commit comments

Comments
 (0)