r26782 - trunk/freenet/src/freenet/pluginmanager

[email protected] Tue, 14 Apr 2009 12:12:16 +0000
Newsgroups gmane.network.freenet.cvs
Message-ID <[email protected]>
Author: saces
Date: 2009-04-14 12:12:16 +0000 (Tue, 14 Apr 2009)
New Revision: 26782

Modified:
   trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
return digest to pool if it was from.

Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java	2009-04-14 11:41:51 UTC (rev 26781)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java	2009-04-14 12:12:16 UTC (rev 26782)
@@ -983,10 +983,13 @@
 		MessageDigest hash = null;
 		FileInputStream fis = null;
 		BufferedInputStream bis = null;
+		boolean wasFromDigest256Pool = false;
+		String result;
 
 		try {
 			if ("SHA-256".equals(digest)) {
 				hash = SHA256.getMessageDigest(); // grab digest from pool
+				wasFromDigest256Pool = true;
 			} else {
 				hash = MessageDigest.getInstance(digest);
 			}
@@ -999,13 +1002,16 @@
 			while((len = bis.read(buffer)) > -1) {
 				hash.update(buffer, 0, len);
 			}
+			result = HexUtil.bytesToHex(hash.digest());
+			if (wasFromDigest256Pool)
+				SHA256.returnMessageDigest(hash);
 		} catch(Exception e) {
 			throw new PluginNotFoundException("Error while computing hash '"+digest+"' of the downloaded plugin: " + e, e);
 		} finally {
 			Closer.close(bis);
 			Closer.close(fis);
 		}
-		return HexUtil.bytesToHex(hash.digest());
+		return result;
 	}
 
 	Ticker getTicker() {