mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-04 22:25:39 +00:00
Corrected memory leak issue #4.
This commit is contained in:
@@ -157,6 +157,13 @@ public class FileState {
|
||||
public void setOldFileState(FileState oldFileState) {
|
||||
this.oldFileState = oldFileState;
|
||||
}
|
||||
|
||||
public void deleteOldFileState() {
|
||||
try {
|
||||
oldFileState.getRandomAccessFile().close();
|
||||
oldFileState = null;
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
public Event getFields() {
|
||||
return fields;
|
||||
|
||||
@@ -170,20 +170,17 @@ public class FileWatcher {
|
||||
}
|
||||
|
||||
logger.trace("Refreshing file state");
|
||||
for(File file : newWatchMap.keySet()) {
|
||||
for(FileState state : newWatchMap.values()) {
|
||||
if(logger.isTraceEnabled()) {
|
||||
logger.trace("Refreshing file : " + file.getCanonicalPath());
|
||||
logger.trace("Refreshing file : " + state.getFile());
|
||||
}
|
||||
FileState state = newWatchMap.get(file);
|
||||
FileState oldState = state.getOldFileState();
|
||||
if(oldState == null) {
|
||||
logger.trace("File has been truncated or created, not retrieving pointer");
|
||||
} else {
|
||||
logger.trace("File has not been truncated or created, retrieving pointer");
|
||||
state.setPointer(oldState.getPointer());
|
||||
try {
|
||||
oldState.getRandomAccessFile().close();
|
||||
} catch(Exception e) {}
|
||||
state.deleteOldFileState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user