From: David ‘Bombe’ Roden Date: Thu, 11 Jun 2015 21:35:49 +0000 (+0200) Subject: Only free bucket after the insert is done X-Git-Tag: 0.9-rc1^2~4^2~1 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f95e0b9700d6d50dedda280da2378cbc81e55efb;p=Sone.git Only free bucket after the insert is done --- diff --git a/pom.xml b/pom.xml index fac0f31..4309f05 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ org.freenetproject fred - 0.7.5.1467.99.1 + 0.7.5.1467.99.3 provided diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index e3a215a..cfc1309 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -161,6 +161,7 @@ public class FreenetInterface { FreenetURI targetUri = key.getInsertURI().setDocName(filenameHint); InsertContext insertContext = client.getInsertContext(true); RandomAccessBucket bucket = new ArrayBucket(temporaryImage.getImageData()); + insertToken.setBucket(bucket); ClientMetadata metadata = new ClientMetadata(temporaryImage.getMimeType()); InsertBlock insertBlock = new InsertBlock(bucket, metadata, targetUri); try { @@ -168,8 +169,6 @@ public class FreenetInterface { insertToken.setClientPutter(clientPutter); } catch (InsertException ie1) { throw new SoneInsertException("Could not start image insert.", ie1); - } finally { - bucket.free(); } } @@ -406,6 +405,7 @@ public class FreenetInterface { /** The client putter. */ private ClientPutter clientPutter; + private Bucket bucket; /** The final URI. */ private volatile FreenetURI resultingUri; @@ -437,6 +437,10 @@ public class FreenetInterface { eventBus.post(new ImageInsertStartedEvent(image)); } + public void setBucket(Bucket bucket) { + this.bucket = bucket; + } + // // ACTIONS // @@ -475,6 +479,7 @@ public class FreenetInterface { } else { eventBus.post(new ImageInsertFailedEvent(image, insertException)); } + bucket.free(); } /** @@ -508,6 +513,7 @@ public class FreenetInterface { @SuppressWarnings("synthetic-access") public void onSuccess(BaseClientPutter clientPutter) { eventBus.post(new ImageInsertFinishedEvent(image, resultingUri)); + bucket.free(); } }