Fix leak, add LeakDetect sub-command

This commit is contained in:
creeper123123321 2018-09-02 19:47:21 -03:00
parent 7920a6add1
commit 7affe9f332
5 changed files with 71 additions and 4 deletions

View File

@ -24,7 +24,7 @@
package com.github.creeper123123321.viarift;
import com.github.creeper123123321.viarift.platform.VRCommandHandler;
import com.github.creeper123123321.viarift.commands.VRCommandHandler;
import com.github.creeper123123321.viarift.platform.VRInjector;
import com.github.creeper123123321.viarift.platform.VRLoader;
import com.github.creeper123123321.viarift.platform.VRPlatform;

View File

@ -22,9 +22,17 @@
* SOFTWARE.
*/
package com.github.creeper123123321.viarift.platform;
package com.github.creeper123123321.viarift.commands;
import com.github.creeper123123321.viarift.commands.subs.LeakDetectSubCommand;
import us.myles.ViaVersion.commands.ViaCommandHandler;
public class VRCommandHandler extends ViaCommandHandler {
{
try {
registerSubCommand(new LeakDetectSubCommand());
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,59 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viarift.commands.subs;
import io.netty.util.ResourceLeakDetector;
import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.command.ViaSubCommand;
import java.util.Arrays;
public class LeakDetectSubCommand extends ViaSubCommand {
@Override
public String name() {
return "leakdetect";
}
@Override
public String description() {
return "Sets ResourceLeakDetector level";
}
@Override
public boolean execute(ViaCommandSender viaCommandSender, String[] strings) {
if (strings.length == 1) {
try {
ResourceLeakDetector.Level level = ResourceLeakDetector.Level.valueOf(strings[0]);
ResourceLeakDetector.setLevel(level);
viaCommandSender.sendMessage("Set leak detector level to " + level);
} catch (IllegalArgumentException e) {
viaCommandSender.sendMessage("Invalid level (" + Arrays.toString(ResourceLeakDetector.Level.values()) +")");
}
} else {
viaCommandSender.sendMessage("Current leak detection level is " + ResourceLeakDetector.getLevel());
}
return true;
}
}

View File

@ -71,7 +71,7 @@ public class VRInHandler extends ByteToMessageDecoder {
buf.clear();
buf.writeBytes(newPacket);
} catch (Exception e) {
buf.clear();
buf.release();
throw e;
} finally {
newPacket.release();

View File

@ -88,7 +88,7 @@ public class VROutHandler extends MessageToByteEncoder {
pre.writeBytes(newPacket);
}
} catch (Exception e) {
pre.clear();
pre.release();
throw e;
} finally {
newPacket.release();