mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-13 15:28:13 +02:00
Fixed a possible buffer memory leak in GeolocationCache on first enable
http://www.evanjones.ca/java-native-leak-bug.html "TL;DR: Always close GZIPInputStream and GZIPOutputStream since they use native memory via zlib."
This commit is contained in:
parent
3ae0855ef5
commit
764a1c661c
@ -16,6 +16,7 @@ import com.maxmind.geoip2.record.Country;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
@ -147,8 +148,12 @@ public class GeolocationCache implements SubSystem {
|
||||
return;
|
||||
}
|
||||
URL downloadSite = new URL("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz");
|
||||
try (ReadableByteChannel rbc = Channels.newChannel(new GZIPInputStream(downloadSite.openStream()));
|
||||
FileOutputStream fos = new FileOutputStream(getInstance().geolocationDB.getAbsoluteFile())) {
|
||||
try (
|
||||
InputStream in = downloadSite.openStream();
|
||||
GZIPInputStream gzipIn = new GZIPInputStream(in);
|
||||
ReadableByteChannel rbc = Channels.newChannel(gzipIn);
|
||||
FileOutputStream fos = new FileOutputStream(getInstance().geolocationDB.getAbsoluteFile())
|
||||
) {
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
@ -92,8 +92,10 @@ public abstract class Response {
|
||||
? getContent()
|
||||
: locale.replaceMatchingLanguage(getContent());
|
||||
|
||||
try (GZIPOutputStream out = new GZIPOutputStream(exchange.getResponseBody());
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(sentContent.getBytes(StandardCharsets.UTF_8))) {
|
||||
try (
|
||||
GZIPOutputStream out = new GZIPOutputStream(exchange.getResponseBody());
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(sentContent.getBytes(StandardCharsets.UTF_8))
|
||||
) {
|
||||
byte[] buffer = new byte[2048];
|
||||
int count;
|
||||
while ((count = bis.read(buffer)) != -1) {
|
||||
|
Loading…
Reference in New Issue
Block a user