Update StringUtils.java (#696)

资源泄漏
pull/702/head
18331247943 2021-11-16 12:19:44 +08:00 committed by GitHub
parent 38262e06b2
commit 7167f29276
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -217,14 +217,17 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
*/
public static String getLocalCityInfo(String ip) {
try {
DataBlock dataBlock = new DbSearcher(config, file.getPath())
.binarySearch(ip);
DbSearcher dbSearcher = new DbSearcher(config, file.getPath());
DataBlock dataBlock = dbSearcher.binarySearch(ip);
String region = dataBlock.getRegion();
String address = region.replace("0|", "");
char symbol = '|';
if (address.charAt(address.length() - 1) == symbol) {
address = address.substring(0, address.length() - 1);
}
if (dataBlock!=null){
dbSearcher.close();
}
return address.equals(ElAdminConstant.REGION) ? "内网IP" : address;
} catch (Exception e) {
log.error(e.getMessage(), e);