From 2b6b7b899e567e5c09c59ce932a5d58ee2ae45c6 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Wed, 9 Jan 2013 00:01:33 -0500 Subject: [PATCH] Attempting to fix some possible memory leaks. Son't know if I'm actually helping anything though. --- .../java/com/gmail/nossr50/spout/SpoutStuff.java | 14 ++++++++++++-- src/main/java/com/gmail/nossr50/util/Database.java | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java b/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java index 60ba61906..ec96d551b 100644 --- a/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java +++ b/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java @@ -48,6 +48,7 @@ public class SpoutStuff { * @param theFilePath The name of the file path */ private static void writeFile(String theFileName, String theFilePath) { + InputStream is = null; OutputStream os = null; JarFile jar = null; @@ -56,7 +57,7 @@ public class SpoutStuff { jar = new JarFile(mcMMO.mcmmo); JarEntry entry = jar.getJarEntry("resources/" + theFileName); - InputStream is = jar.getInputStream(entry); + is = jar.getInputStream(entry); byte[] buf = new byte[2048]; int nbRead; @@ -66,6 +67,8 @@ public class SpoutStuff { while ((nbRead = is.read(buf)) != -1) { os.write(buf, 0, nbRead); } + + os.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -74,9 +77,16 @@ public class SpoutStuff { e.printStackTrace(); } finally { + if (is != null) { + try { + is.close(); + } + catch (IOException ex) { + ex.printStackTrace(); + } + } if (os != null) { try { - os.flush(); os.close(); } catch (IOException ex) { diff --git a/src/main/java/com/gmail/nossr50/util/Database.java b/src/main/java/com/gmail/nossr50/util/Database.java index 8f94d5d1d..84a2c2353 100644 --- a/src/main/java/com/gmail/nossr50/util/Database.java +++ b/src/main/java/com/gmail/nossr50/util/Database.java @@ -155,7 +155,7 @@ public class Database { PreparedStatement statement = null; try { - if(!checkConnected()) return; + if(!checkConnected()) return; statement = connection.prepareStatement(sql); resultSet = statement.executeQuery();