Permalink
Browse files

Image handle cleanup, make sure it gets closed

  • Loading branch information...
1 parent 421dbf3 commit ba4fd7b88403046e8144adb13ddcb634b1e39483 Peter J. Martel committed Nov 18, 2011
View
2 bindings/java/src/org/sleuthkit/datamodel/FileSystem.java
@@ -100,7 +100,7 @@ public long getSize() {
* @return a filesystem pointer from the sleuthkit
* @throws TskException
*/
- public long getFileSystemHandle() throws TskException{
+ long getFileSystemHandle() throws TskException{
if (filesystemHandle == 0){
filesystemHandle = SleuthkitJNI.openFs(parent.getImageHandle(), img_offset);
}
View
11 bindings/java/src/org/sleuthkit/datamodel/FileSystemParent.java
@@ -23,10 +23,17 @@
* object.
*/
-public interface FileSystemParent extends Content {
+public abstract class FileSystemParent extends AbstractContent{
+
+ FileSystemParent(SleuthkitCase db, long obj_id) {
+ super(db, obj_id);
+ }
+
+
+
/**
* get the handle to the sleuthkit image info object
* @return the object pointer
*/
- public long getImageHandle();
+ abstract long getImageHandle() throws TskException;
}
View
19 bindings/java/src/org/sleuthkit/datamodel/Image.java
@@ -26,7 +26,7 @@
* Populated based on data in database.
*/
-public class Image extends AbstractContent implements FileSystemParent {
+public class Image extends FileSystemParent {
//data about image
private long type, ssize;
@@ -50,7 +50,6 @@ protected Image(SleuthkitCase db, long obj_id, long type, long ssize, String nam
this.ssize = ssize;
this.name = name;
this.paths = paths;
- this.imageHandle = SleuthkitJNI.openImage(paths);
}
/**
@@ -66,9 +65,21 @@ public void setPath(String newPath) {
* @return the object pointer
*/
@Override
- public long getImageHandle() {
+ public long getImageHandle() throws TskException {
+ if (imageHandle == 0) {
+ imageHandle = SleuthkitJNI.openImage(paths);
+ }
+
return imageHandle;
}
+
+ @Override
+ public void finalize() throws Throwable {
+ super.finalize();
+ if(imageHandle != 0){
+ SleuthkitJNI.closeImg(imageHandle);
+ }
+ }
/**
* read from the image
@@ -80,7 +91,7 @@ public long getImageHandle() {
@Override
public byte[] read(long offset, long len) throws TskException {
// read from the image
- return SleuthkitJNI.readImg(imageHandle, offset, len);
+ return SleuthkitJNI.readImg(getImageHandle(), offset, len);
}
/**
View
4 bindings/java/src/org/sleuthkit/datamodel/Volume.java
@@ -25,7 +25,7 @@
* Represents a volume in a VolumeSystem.
* Populated based on data in database.
*/
-public class Volume extends AbstractContent implements FileSystemParent {
+public class Volume extends FileSystemParent {
// @@@ We should mark these as private and comment somewhere what the units are (bytes, sectors, etc.)
long addr, start, length, flags;
String desc;
@@ -206,7 +206,7 @@ public static String vsFlagToString(long vsFlag){
}
@Override
- public long getImageHandle() {
+ public long getImageHandle() throws TskException {
return getParent().getParent().getImageHandle();
}

0 comments on commit ba4fd7b

Please sign in to comment.