From a760b4b6d0202e49c7f5cf22b04360b0d05653b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Sun, 27 May 2018 18:04:45 +0200 Subject: [PATCH] Fix cluster leak when truncating files --- src/table.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/table.rs b/src/table.rs index cac50b4..a3c856d 100644 --- a/src/table.rs +++ b/src/table.rs @@ -361,8 +361,11 @@ impl <'a, 'b> ClusterIterator<'a, 'b> { pub(crate) fn truncate(&mut self) -> io::Result<()> { match self.cluster { Some(n) => { - write_fat(&mut self.fat, self.fat_type, n, FatValue::EndOfChain)?; + // Move to the next cluster self.next(); + // Mark previous cluster as end of chain + write_fat(&mut self.fat, self.fat_type, n, FatValue::EndOfChain)?; + // Free rest of chain self.free() }, None => Ok(()),