From 28f4c38b8139518a7a13787c25c891715fb42bc6 Mon Sep 17 00:00:00 2001 From: Juhyung Park Date: Wed, 28 Aug 2019 16:58:38 +0900 Subject: [PATCH] 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. --- sync/src/block/downloader/header.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sync/src/block/downloader/header.rs b/sync/src/block/downloader/header.rs index dc6d653572..74d8f14118 100644 --- a/sync/src/block/downloader/header.rs +++ b/sync/src/block/downloader/header.rs @@ -179,6 +179,7 @@ impl HeaderDownloader { pub fn mark_as_imported(&mut self, hashes: Vec) { for hash in hashes { self.queued.remove(&hash); + self.downloaded.remove(&hash); if self.best_hash == hash { self.pivot = Pivot { @@ -188,6 +189,7 @@ impl HeaderDownloader { } } self.queued.shrink_to_fit(); + self.downloaded.shrink_to_fit(); } pub fn mark_as_queued(&mut self, hashes: Vec) {