From 2b3e2992e7ea5d615531fd8c683f0f58cc456f42 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 18 Mar 2022 15:34:56 +0100 Subject: [client] Cleanup chunk data lists when upload finished or is cancelled --- .../dozmod/filetransfer/AsyncHashGenerator.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'dozentenmodul/src') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java index 83e89302..cf593200 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java @@ -51,6 +51,8 @@ public class AsyncHashGenerator extends Thread { private final List chunkHashes; private final List chunkList; private long nextReadMsg, nextDoneMsg, nextSendingMsg; // for debug spam :-( + private boolean readingDone = false; + private boolean hashingDone = false; private volatile boolean isCanceled = false; @@ -74,6 +76,7 @@ public class AsyncHashGenerator extends Thread { this.uploadToken = token; submitHashes(false); } + cleanupIfDone(); } @Override @@ -134,6 +137,8 @@ public class AsyncHashGenerator extends Thread { } } finally { Util.safeClose(file); + readingDone = true; + cleanupIfDone(); } } @@ -219,6 +224,26 @@ public class AsyncHashGenerator extends Thread { isCanceled = true; } } + if (wasLastChunk) { + hashingDone = true; + cleanupIfDone(); + } + } + + /** + * Drop references to all the chunk metadata - in case someone is still holding + * a reference to this class, at least we will not prevent this stuff from being + * garbage collected. + */ + private void cleanupIfDone() { + if (uploadToken == null && !isCanceled) + return; + if (!readingDone) + return; + if (!hashingDone && !isCanceled) + return; + chunkHashes.clear(); + chunkList.clear(); } /** -- cgit v1.2.3-55-g7522