From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3664C623F2 for ; Thu, 20 Jan 2022 11:30:06 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 25A7E23261 for ; Thu, 20 Jan 2022 11:30:06 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 589EC23256 for ; Thu, 20 Jan 2022 11:30:05 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 0421D46C91 for ; Thu, 20 Jan 2022 11:30:05 +0100 (CET) Date: Thu, 20 Jan 2022 11:30:04 +0100 From: Wolfgang Bumiller To: Dominik Csapak Cc: pbs-devel@lists.proxmox.com Message-ID: <20220120103004.va2fqclwvb3gzuju@olga.proxmox.com> References: <20220120101608.1062152-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220120101608.1062152-1-d.csapak@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.398 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] applied: [PATCH proxmox-backup] pbs-tools: LruCache: implement Drop X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Jan 2022 10:30:06 -0000 applied, thanks On Thu, Jan 20, 2022 at 11:16:08AM +0100, Dominik Csapak wrote: > this fixes the leaked memory for the cache, as we had only pointers > in the map/list which were freed, not the underlying chunks > > moves the 'clear' implementation out of the trait bounds so that > Drop can reuse it > > this is used e.g. for file download from a pxar > > Signed-off-by: Dominik Csapak > --- > pbs-tools/src/lru_cache.rs | 24 ++++++++++++++++-------- > 1 file changed, 16 insertions(+), 8 deletions(-) > > diff --git a/pbs-tools/src/lru_cache.rs b/pbs-tools/src/lru_cache.rs > index b1c0c6ac..fbd7673a 100644 > --- a/pbs-tools/src/lru_cache.rs > +++ b/pbs-tools/src/lru_cache.rs > @@ -100,9 +100,25 @@ pub struct LruCache { > _marker: PhantomData>>, > } > > +impl Drop for LruCache { > + fn drop (&mut self) { > + self.clear(); > + } > +} > + > // trivial: if our contents are Send, the whole cache is Send > unsafe impl Send for LruCache {} > > +impl LruCache { > + /// Clear all the entries from the cache. > + pub fn clear(&mut self) { > + // This frees only the HashMap with the node pointers. > + self.map.clear(); > + // This frees the actual nodes and resets the list head and tail. > + self.list.clear(); > + } > +} > + > impl LruCache { > /// Create LRU cache instance which holds up to `capacity` nodes at once. > pub fn new(capacity: usize) -> Self { > @@ -115,14 +131,6 @@ impl LruCache { > } > } > > - /// Clear all the entries from the cache. > - pub fn clear(&mut self) { > - // This frees only the HashMap with the node pointers. > - self.map.clear(); > - // This frees the actual nodes and resets the list head and tail. > - self.list.clear(); > - } > - > /// Insert or update an entry identified by `key` with the given `value`. > /// This entry is placed as the most recently used node at the head. > pub fn insert(&mut self, key: K, value: V) { > -- > 2.30.2