From 685fa48a6b6223015bf20b2ea1df4ad1c9e5161f Mon Sep 17 00:00:00 2001 From: romanman Date: Mon, 14 Jul 2014 22:01:14 +0300 Subject: [PATCH] Memory leak fix: + cause of the memory leak was not closing file writer for the state dump --- .../src/main/java/org/ethereum/db/Repository.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/db/Repository.java b/ethereumj-core/src/main/java/org/ethereum/db/Repository.java index b48c47f7..e37d9f56 100644 --- a/ethereumj-core/src/main/java/org/ethereum/db/Repository.java +++ b/ethereumj-core/src/main/java/org/ethereum/db/Repository.java @@ -316,13 +316,15 @@ public class Repository { blockNumber, txNumber, txHash.substring(0, 8)); File dumpFile = new File(System.getProperty("user.dir") + "/" + dir + fileName); + FileWriter fw = null; + BufferedWriter bw = null; try { dumpFile.getParentFile().mkdirs(); dumpFile.createNewFile(); - FileWriter fw = new FileWriter(dumpFile.getAbsoluteFile()); - BufferedWriter bw = new BufferedWriter(fw); + fw = new FileWriter(dumpFile.getAbsoluteFile()); + bw = new BufferedWriter(fw); List keys = this.detailsDB.dumpKeys(); @@ -351,9 +353,13 @@ public class Repository { // {address: x, nonce: n1, balance: b1, stateRoot: s1, codeHash: c1, code: c2, sotrage: [key: k1, value: v1, key:k2, value: v2 ] } } - bw.close(); } catch (IOException e) { logger.error(e.getMessage(), e); + } finally { + try { + if (bw != null)bw.close(); + if (fw != null)fw.close(); + } catch (IOException e) {e.printStackTrace();} } }