diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 429e85bf37..3bb87f96b6 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -360,6 +360,7 @@ public class Case { try { this.xmlcm.close(); // close the xmlcm this.db.close(); + services.close(); } catch (Exception e) { throw new CaseActionException("Error while trying to close the current case.", e); } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/FileManager.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/FileManager.java index 2fb61bd002..786370e9d2 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/FileManager.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/FileManager.java @@ -4,6 +4,9 @@ */ package org.sleuthkit.autopsy.casemodule.services; +import java.io.Closeable; +import java.io.IOException; +import java.util.Collections; import java.util.List; import org.sleuthkit.datamodel.FsContent; import org.sleuthkit.datamodel.SleuthkitCase; @@ -12,7 +15,7 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Abstraction to facilitate access to files and directories. */ -public class FileManager { +public class FileManager implements Closeable { private SleuthkitCase tskCase; @@ -26,7 +29,10 @@ public class FileManager { * given fileName */ public List findFiles(String fileName) throws TskCoreException { - return tskCase.findFiles(fileName); + if (tskCase == null) { + throw new TskCoreException("Attemtped to use FileManager after it was closed."); + } + return tskCase.findFiles(fileName); } /** @@ -36,7 +42,10 @@ public class FileManager { * fileName and whose parent directory contains dirName. */ public List findFiles(String fileName, String dirName) throws TskCoreException { - return tskCase.findFiles(fileName, dirName); + if (tskCase == null) { + throw new TskCoreException("Attemtped to use FileManager after it was closed."); + } + return tskCase.findFiles(fileName, dirName); } /** @@ -46,7 +55,10 @@ public class FileManager { * fileName and that were inside a directory described by parentFsContent. */ public List findFiles(String fileName, FsContent parentFsContent) throws TskCoreException { - return findFiles(fileName, parentFsContent.getName()); + if (tskCase == null) { + throw new TskCoreException("Attemtped to use FileManager after it was closed."); + } + return findFiles(fileName, parentFsContent.getName()); } /** @@ -55,7 +67,15 @@ public class FileManager { * @return a list of FsContent that have the given file path. */ public List openFiles(String filePath) throws TskCoreException { - return tskCase.openFiles(filePath); + if (tskCase == null) { + throw new TskCoreException("Attemtped to use FileManager after it was closed."); + } + return tskCase.openFiles(filePath); } + + @Override + public void close() throws IOException { + tskCase = null; + } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java index af16268207..d1844b7c7f 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java @@ -4,15 +4,25 @@ */ package org.sleuthkit.autopsy.casemodule.services; +import java.io.Closeable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.sleuthkit.datamodel.SleuthkitCase; /** * * @author mciver */ -public class Services { +public class Services implements Closeable { private SleuthkitCase tskCase; + + // NOTE: all new services added to Services class must be added to this list + // of services. + List services = new ArrayList(); + + // services private FileManager fileManager; public Services(SleuthkitCase tskCase) { @@ -22,7 +32,16 @@ public class Services { public FileManager getFileManager() { if (fileManager == null) { fileManager = new FileManager(tskCase); + services.add(fileManager); } return fileManager; } + + @Override + public void close() throws IOException { + // close all services + for (Closeable service : services) { + service.close(); + } + } }