mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-19 10:11:02 +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.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
@ -147,8 +148,12 @@ public class GeolocationCache implements SubSystem {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
URL downloadSite = new URL("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz");
|
URL downloadSite = new URL("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz");
|
||||||
try (ReadableByteChannel rbc = Channels.newChannel(new GZIPInputStream(downloadSite.openStream()));
|
try (
|
||||||
FileOutputStream fos = new FileOutputStream(getInstance().geolocationDB.getAbsoluteFile())) {
|
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);
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,8 +92,10 @@ public abstract class Response {
|
|||||||
? getContent()
|
? getContent()
|
||||||
: locale.replaceMatchingLanguage(getContent());
|
: locale.replaceMatchingLanguage(getContent());
|
||||||
|
|
||||||
try (GZIPOutputStream out = new GZIPOutputStream(exchange.getResponseBody());
|
try (
|
||||||
ByteArrayInputStream bis = new ByteArrayInputStream(sentContent.getBytes(StandardCharsets.UTF_8))) {
|
GZIPOutputStream out = new GZIPOutputStream(exchange.getResponseBody());
|
||||||
|
ByteArrayInputStream bis = new ByteArrayInputStream(sentContent.getBytes(StandardCharsets.UTF_8))
|
||||||
|
) {
|
||||||
byte[] buffer = new byte[2048];
|
byte[] buffer = new byte[2048];
|
||||||
int count;
|
int count;
|
||||||
while ((count = bis.read(buffer)) != -1) {
|
while ((count = bis.read(buffer)) != -1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user