Skip to content

Commit

Permalink
Fix memory leak..
Browse files Browse the repository at this point in the history
  • Loading branch information
rorist committed Jan 25, 2015
1 parent b693f01 commit bbb895b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/info/lamatricexiste/network/Network/HardwareAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ public HardwareAddress(Activity activity) {

public static String getHardwareAddress(String ip) {
String hw = NetInfo.NOMAC;
BufferedReader bufferedReader = null;
try {
if (ip != null) {
String ptrn = String.format(MAC_RE, ip.replace(".", "\\."));
Pattern pattern = Pattern.compile(ptrn);
BufferedReader bufferedReader = new BufferedReader(new FileReader("/proc/net/arp"), BUF);
bufferedReader = new BufferedReader(new FileReader("/proc/net/arp"), BUF);
String line;
Matcher matcher;
while ((line = bufferedReader.readLine()) != null) {
Expand All @@ -57,13 +58,20 @@ public static String getHardwareAddress(String ip) {
break;
}
}
bufferedReader.close();
} else {
Log.e(TAG, "ip is null");
}
} catch (IOException e) {
Log.e(TAG, "Can't open/read file ARP: " + e.getMessage());
return hw;
} finally {
try {
if(bufferedReader != null) {
bufferedReader.close();
}
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
}
return hw;
}
Expand Down

0 comments on commit bbb895b

Please sign in to comment.