Potential memory leaks fixed.

This commit is contained in:
retrooper committed 2021-06-20 21:28:19 +02:00
1 parent 6b86d7fdc6
commit ccf401ff6d
11 files changed
+106 -3

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -33,6 +33,7 @@ import io.github.retrooper.packetevents.processor.PacketProcessorInternal;
import io.github.retrooper.packetevents.settings.PacketEventsSettings;
import io.github.retrooper.packetevents.updatechecker.UpdateChecker;
import io.github.retrooper.packetevents.utils.entityfinder.EntityFinderUtils;
import io.github.retrooper.packetevents.utils.guava.GuavaUtils;
import io.github.retrooper.packetevents.utils.netty.bytebuf.ByteBufUtil;
import io.github.retrooper.packetevents.utils.netty.bytebuf.ByteBufUtil_7;
import io.github.retrooper.packetevents.utils.netty.bytebuf.ByteBufUtil_8;
@@ -124,6 +125,8 @@ public final class PacketEvents implements Listener, EventManager {
EntityFinderUtils.load();
getServerUtils().entityCache = GuavaUtils.makeMap();
if (version.isNewerThanOrEquals(ServerVersion.v_1_9)) {
for (WrappedPacketOutEntityEquipment.EquipmentSlot slot : WrappedPacketOutEntityEquipment.EquipmentSlot.values()) {
slot.id = (byte) slot.ordinal();
@@ -0,0 +1,37 @@
/*
*
* * This file is part of packetevents - https://github.com/retrooper/packetevents
* * Copyright (C) 2016-2021 retrooper and contributors
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package io.github.retrooper.packetevents.utils.guava;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.utils.server.ServerVersion;
import java.util.concurrent.ConcurrentMap;
public class GuavaUtils {
public static <T, K>ConcurrentMap<T, K> makeMap() {
if (PacketEvents.get().getServerUtils().getVersion().isNewerThan(ServerVersion.v_1_7_10)) {
return GuavaUtils_8.makeMap();
}
else {
return GuavaUtils_7.makeMap();
}
}
}
@@ -0,0 +1,31 @@
/*
*
* * This file is part of packetevents - https://github.com/retrooper/packetevents
* * Copyright (C) 2016-2021 retrooper and contributors
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package io.github.retrooper.packetevents.utils.guava;
import net.minecraft.util.com.google.common.collect.MapMaker;
import java.util.concurrent.ConcurrentMap;
class GuavaUtils_7 {
static <T, K> ConcurrentMap<T, K> makeMap() {
return new MapMaker().weakValues().makeMap();
}
}
@@ -0,0 +1,31 @@
/*
*
* * This file is part of packetevents - https://github.com/retrooper/packetevents
* * Copyright (C) 2016-2021 retrooper and contributors
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package io.github.retrooper.packetevents.utils.guava;
import com.google.common.collect.MapMaker;
import java.util.concurrent.ConcurrentMap;
class GuavaUtils_8 {
static <T, K> ConcurrentMap<T, K> makeMap() {
return new MapMaker().weakValues().makeMap();
}
}
@@ -33,7 +33,8 @@ public final class ServerUtils {
private boolean geyserClassChecked;
private final NPCManager npcManager = new NPCManager();
private final Map<Integer, Entity> entityIDs = new ConcurrentHashMap<>();
//Initialized in PacketEvents#load
public Map<Integer, Entity> entityCache;
/**
* Get the server version.
@@ -86,11 +87,11 @@ public final class ServerUtils {
@Nullable
public Entity getEntityById(int entityID) {
return entityIDs.get(entityID);
return entityCache.get(entityID);
}
public void cacheEntityById(int entityID, @NotNull Entity entity) {
entityIDs.putIfAbsent(entityID, entity);
entityCache.putIfAbsent(entityID, entity);
}
public boolean isGeyserAvailable() {