Fix a memory leak that doesn't fix until another version is downloaded (can take up to 400mb of ram)

This commit is contained in:
2026-01-07 17:28:42 -07:00
parent fa256dd004
commit e89b0fac8a

View File

@@ -15,6 +15,7 @@ use tauri::{AppHandle, Emitter, Manager};
use tauri_plugin_dialog::{DialogExt, MessageDialogKind};
use tauri_plugin_opener::OpenerExt;
use tauri_plugin_os::platform;
use tokio::io::AsyncReadExt;
use tokio::{io::AsyncWriteExt, time::timeout};
use zip::ZipArchive;
@@ -182,9 +183,26 @@ async fn download(
app.emit("download-hash-checking", format!("{}", &name))
.unwrap();
let mut hasher = Sha512::new();
hasher.update(&tokio::fs::read(download_part_path.clone()).await.unwrap());
let download_hash = format!("{:x}", hasher.finalize());
let download_hash = {
let mut file = tokio::fs::File::open(download_part_path.clone())
.await
.unwrap();
let mut hasher = Sha512::new();
{
let mut buffer = [0; 8192];
loop {
let bytes_read = file.read(&mut buffer).await.unwrap();
if bytes_read == 0 {
break;
}
hasher.update(&buffer[..bytes_read]);
}
}
drop(file);
format!("{:x}", hasher.finalize())
};
if hash != download_hash {
tokio::fs::remove_file(download_part_path.clone())
.await