fixed potential memory leaks

This commit is contained in:
2013-04-16 08:39:23 +02:00
parent d76b1d89a7
commit 3d2702bab2
2 changed files with 24 additions and 8 deletions
@@ -50,12 +50,18 @@ public class FdaqService {
@Override
public void run() {
PrintWriter writer = null;
Socket echoSocket = null;
DataOutputStream out = null;
DataInputStream in = null;
try {
FdaqConfiguration config = FdaqConfiguration.getInstance();
stopAcquisition = false;
Socket echoSocket = new Socket(config.getHostname(), config.getPort());
DataOutputStream out = new DataOutputStream(echoSocket.getOutputStream());
DataInputStream in = new DataInputStream(echoSocket.getInputStream());
echoSocket = new Socket(config.getHostname(), config.getPort());
out = new DataOutputStream(echoSocket.getOutputStream());
in = new DataInputStream(echoSocket.getInputStream());
int nMessages = config.getNelements();
@@ -70,7 +76,7 @@ public class FdaqService {
// open file and write
try(PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)))){
writer = new PrintWriter(new BufferedWriter(new FileWriter(file)));
writer.println("# a" + "\t" + "b1" + "\t" + "b2" + "\t" + "c1" + "\t" + "c2" + "\t" + "d");
@@ -97,8 +103,8 @@ public class FdaqService {
// System.out.println(a + " " + b1 + " " + b2 + " " + c1 + " " + c2 + " " + d);
writer.println(a + "\t" + b1 + "\t" + b2 + "\t" + c1 + "\t" + c2 + "\t" + d);
}
}
writer.close();
out.close();
in.close();
echoSocket.close();
@@ -107,6 +113,16 @@ public class FdaqService {
logger.log(Level.SEVERE, "", e);
}
}
finally{
try{
writer.close();
out.close();
in.close();
echoSocket.close();
} catch (IOException e) {
// Ignore because not relevant at this stage
}
}
}
});
t.start();