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
+2 -2
View File
@@ -9,12 +9,12 @@
<snapshotRepository>
<id>i.snapshots</id>
<name>Artifactory Snapshots</name>
<url>http://slsyoke1/artifactory/libs-snapshots-local</url>
<url>http://yoke.psi.ch/artifactory/libs-snapshots-local</url>
</snapshotRepository>
<repository>
<id>i.releases</id>
<name>Atrifactory Releases</name>
<url>http://slsyoke1/artifactory/libs-releases-local</url>
<url>http://yoke.psi.ch/artifactory/libs-releases-local</url>
</repository>
</distributionManagement>
</project>
@@ -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();