mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 18:33:08 +00:00
Merge pull request #188 from KAMKEEL/codex/find-and-fix-memory-leak-issues
Fix memory leaks by closing streams
This commit is contained in:
18 files changed
+96
-60
No files matched your search
@@ -79,7 +79,9 @@ public class BankController {
|
||||
}
|
||||
|
||||
private void loadBanks(File file) throws IOException {
|
||||
loadBanks(CompressedStreamTools.readCompressed(new FileInputStream(file)));
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
loadBanks(CompressedStreamTools.readCompressed(fis));
|
||||
}
|
||||
}
|
||||
|
||||
public void loadBanks(NBTTagCompound nbttagcompound1) throws IOException {
|
||||
|
||||
@@ -120,7 +120,10 @@ public class DialogController implements IDialogHandler {
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
}
|
||||
NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
NBTTagCompound nbttagcompound1;
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
nbttagcompound1 = CompressedStreamTools.readCompressed(fis);
|
||||
}
|
||||
NBTTagList list = nbttagcompound1.getTagList("Data", 10);
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
@@ -40,7 +40,10 @@ public class GlobalDataController {
|
||||
}
|
||||
|
||||
private void loadData(File file) throws Exception {
|
||||
NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
NBTTagCompound nbttagcompound1;
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
nbttagcompound1 = CompressedStreamTools.readCompressed(fis);
|
||||
}
|
||||
itemGiverId = nbttagcompound1.getInteger("itemGiverId");
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,10 @@ public class PlayerDataController {
|
||||
try {
|
||||
File file = new File(saveDir, filename);
|
||||
if (file.exists()) {
|
||||
NBTTagCompound comp = CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
NBTTagCompound comp;
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
comp = CompressedStreamTools.readCompressed(fis);
|
||||
}
|
||||
file.delete();
|
||||
file = new File(saveDir, filename + "_old");
|
||||
if (file.exists())
|
||||
@@ -197,7 +200,9 @@ public class PlayerDataController {
|
||||
try {
|
||||
File file = new File(saveDir, filename + "_old");
|
||||
if (file.exists()) {
|
||||
return CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
return CompressedStreamTools.readCompressed(fis);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -112,7 +112,10 @@ public class QuestController implements IQuestHandler {
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
}
|
||||
NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
NBTTagCompound nbttagcompound1;
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
nbttagcompound1 = CompressedStreamTools.readCompressed(fis);
|
||||
}
|
||||
lastUsedCatID = nbttagcompound1.getInteger("lastID");
|
||||
lastUsedQuestID = nbttagcompound1.getInteger("lastQuestID");
|
||||
NBTTagList list = nbttagcompound1.getTagList("Data", 10);
|
||||
|
||||
@@ -94,7 +94,10 @@ public class RecipeController implements IRecipeHandler {
|
||||
}
|
||||
|
||||
private void loadCategories(File file) throws Exception {
|
||||
NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
NBTTagCompound nbttagcompound1;
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
nbttagcompound1 = CompressedStreamTools.readCompressed(fis);
|
||||
}
|
||||
nextId = nbttagcompound1.getInteger("LastId");
|
||||
nextAnvilId = nbttagcompound1.getInteger("LastAnvilId");
|
||||
NBTTagList list = nbttagcompound1.getTagList("Data", 10);
|
||||
|
||||
@@ -63,7 +63,10 @@ public class ServerCloneController implements ICloneHandler {
|
||||
|
||||
private Map<Integer, Map<String, NBTTagCompound>> loadOldClones(File file) throws Exception {
|
||||
Map<Integer, Map<String, NBTTagCompound>> clones = new HashMap<Integer, Map<String, NBTTagCompound>>();
|
||||
NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
NBTTagCompound nbttagcompound1;
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
nbttagcompound1 = CompressedStreamTools.readCompressed(fis);
|
||||
}
|
||||
NBTTagList list = nbttagcompound1.getTagList("Data", 10);
|
||||
if (list == null) {
|
||||
return clones;
|
||||
|
||||
@@ -66,7 +66,10 @@ public class TransportController implements ITransportHandler {
|
||||
public void loadCategories(File file) throws IOException {
|
||||
HashMap<Integer, TransportLocation> locations = new HashMap<Integer, TransportLocation>();
|
||||
HashMap<Integer, TransportCategory> categories = new HashMap<Integer, TransportCategory>();
|
||||
NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
NBTTagCompound nbttagcompound1;
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
nbttagcompound1 = CompressedStreamTools.readCompressed(fis);
|
||||
}
|
||||
lastUsedID = nbttagcompound1.getInteger("lastID");
|
||||
NBTTagList list = nbttagcompound1.getTagList("NPCTransportCategories", 10);
|
||||
if (list == null) {
|
||||
|
||||
Reference in new issue
Block a user